#include "WarningPanel.h" WarningPanel::WarningPanel(QWidget* parent): QFrame(parent), warningLabel(new QLabel) { initPanel(); setLayout(createWarningLayout()); } void WarningPanel::initPanel() { setFrameStyle(QFrame::StyledPanel); setPalette(QPalette("#ffffcc")); setAutoFillBackground(true); hide(); } QHBoxLayout* WarningPanel::createWarningLayout() { QHBoxLayout* warningLt = new QHBoxLayout; warningLt->addWidget(createWarningIconLabel(), 0, Qt::AlignTop); warningLt->addWidget(warningLabel, 1); warningLt->addWidget(createWarningCloseButton(), 0, Qt::AlignTop); return warningLt; } void WarningPanel::setText(const QString& text) { warningLabel->setText(text); } QLabel* WarningPanel::createWarningIconLabel() const { QLabel* label = new QLabel; label->setPixmap( QPixmap(":/images/warning.png").scaled( 24, 24, Qt::KeepAspectRatio, Qt::SmoothTransformation ) ); return label; } QToolButton* WarningPanel::createWarningCloseButton() const { QToolButton* button = new QToolButton; button->setAutoRaise(true); button->setIcon(QIcon(":/images/gray-cross.png")); button->setShortcut(Qt::Key_Escape); connect(button, SIGNAL(clicked()), this, SLOT(hide())); return button; }