/*! * @brief Create and setup a cutom TitleBar * * Create and setup a cutom TitleBar */ TitleBar::TitleBar(QWidget *parent, QWidget *mainw) : QWidget(parent) { mainwin = mainw; mMaxNormal = false; setObjectName("titlebar"); // Top right buttons/icons mMinimizeButton = new QToolButton(this); mMaximizeButton = new QToolButton(this); mCloseButton = new QToolButton(this); QIcon closeicon = QIcon(":/winicons/closeNorm.png"); QIcon minicon = QIcon(":/winicons/minNorm.png"); maxicon = QIcon(":/winicons/maxNorm.png"); resticon = QIcon(":/winicons/restNorm.png"); mCloseButton->setIcon(closeicon); mCloseButton->setObjectName("closeWindowBtn"); mMinimizeButton->setIcon(minicon); mMaximizeButton->setIcon(maxicon); // Logo QLabel *logo = new QLabel(); QPixmap p = QIcon("://logo3.png").pixmap(QSize(22, 22)); logo->setPixmap(p.scaled(22, 22, Qt::KeepAspectRatio, Qt::SmoothTransformation)); logo->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); // Title QFont f("Arial", 12, QFont::Bold); mLabel = new QLabel(); mLabel->setText(mainwin->windowTitle()); mLabel->setFont(f); mLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); // Title layout QHBoxLayout *hbox = new QHBoxLayout(this); hbox->setSpacing(0); hbox->setMargin(0); hbox->addWidget(logo); hbox->addWidget(mLabel); hbox->addWidget(mMinimizeButton); hbox->addWidget(mMaximizeButton); hbox->addWidget(mCloseButton); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); connect(mCloseButton, SIGNAL(clicked()), mainwin, SLOT(close())); connect(mMinimizeButton, SIGNAL(clicked()), this, SLOT(showSmall())); connect(mMaximizeButton, SIGNAL(clicked()), this, SLOT(showMaxRestore())); setMaximumHeight(24); }
TitleBar::TitleBar(QWidget *parent, QString* title) { // Don't let this widget inherit the parent's backround color // setAutoFillBackground(true); // Use a brush with a Highlight color role to render the background setBackgroundRole(QPalette::NoRole); minimize = new QToolButton(this); minimize->setObjectName("minimizeButton"); maximize = new QToolButton(this); maximize->setObjectName("maximizeButton"); close = new QToolButton(this); close->setObjectName("closeButton"); // Use the style to set the button pixmaps QPixmap pix = style()->standardPixmap(QStyle::SP_TitleBarCloseButton); close->setIcon(pix); close->setAutoRaise(true); maxPix = style()->standardPixmap(QStyle::SP_TitleBarMaxButton); maximize->setIcon(maxPix); maximize->setAutoRaise(true); pix = style()->standardPixmap(QStyle::SP_TitleBarMinButton); minimize->setIcon(pix); minimize->setAutoRaise(true); restorePix = style()->standardPixmap(QStyle::SP_TitleBarNormalButton); // minimize->setMinimumHeight(20); // close->setMinimumHeight(20); // maximize->setMinimumHeight(20); label = new QLabel(this); label->setAttribute(Qt::WA_Disabled); QHBoxLayout *hbox = new QHBoxLayout(this); hbox->setContentsMargins ( 0,0,0,0 ); hbox->addWidget(label); hbox->addWidget(minimize, 0, Qt::AlignTop); hbox->addWidget(maximize, 0, Qt::AlignTop); hbox->addWidget(close, 0, Qt::AlignTop); hbox->insertStretch(1, 500); hbox->setSpacing(0); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); maxNormal = false; connect(close, SIGNAL( clicked() ), parent->parentWidget(), SLOT(close() ) ); connect(minimize, SIGNAL( clicked() ), this, SLOT(showSmall() ) ); connect(maximize, SIGNAL( clicked() ), this, SLOT(showMaxRestore() ) ); }
int TitleBar::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QWidget::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: showSmall(); break; case 1: showMaxRestore(); break; default: ; } _id -= 2; } return _id; }
CWizTitleBar::CWizTitleBar(QWidget *parent, QWidget* window, QWidget* shadowContainerWidget) : QWidget(parent) , m_window(window) , m_shadowContainerWidget(shadowContainerWidget) , m_oldContentsMargin(10, 10, 10, 10) , m_canResize(true) { // 不继承父组件的背景色 setAutoFillBackground(true); m_minimize = new QToolButton(this); m_maximize = new QToolButton(this); m_close = new QToolButton(this); // 设置按钮图像的样式 QString themeName = Utils::StyleHelper::themeName(); QString strButtonClose = ::WizGetSkinResourceFileName(themeName, "linuxwindowclose"); QString strButtonCloseOn = ::WizGetSkinResourceFileName(themeName, "linuxwindowclose_on"); QString strButtonCloseSelected = ::WizGetSkinResourceFileName(themeName, "linuxwindowclose_selected"); QString strButtonMin = ::WizGetSkinResourceFileName(themeName, "linuxwindowmin"); QString strButtonMinOn = ::WizGetSkinResourceFileName(themeName, "linuxwindowmin_on"); QString strButtonMinSelected = ::WizGetSkinResourceFileName(themeName, "linuxwindowmin_selected"); QString strButtonMax = ::WizGetSkinResourceFileName(themeName, "linuxwindowmax"); QString strButtonMaxOn = ::WizGetSkinResourceFileName(themeName, "linuxwindowmax_on"); QString strButtonMaxSelected = ::WizGetSkinResourceFileName(themeName, "linuxwindowmax_selected"); QString strButtonRestore = ::WizGetSkinResourceFileName(themeName, "linuxwindowrestore"); QString strButtonRestoreOn = ::WizGetSkinResourceFileName(themeName, "linuxwindowrestore_on"); QString strButtonRestoreSelected = ::WizGetSkinResourceFileName(themeName, "linuxwindowrestore_Selected"); m_close->setStyleSheet(QString("QToolButton{ border-image:url(%1);background:none;}" "QToolButton:hover{border-image:url(%2); background:none;}" "QToolButton::pressed{border-image:url(%3); background:none;}") .arg(strButtonClose).arg(strButtonCloseOn).arg(strButtonCloseSelected)); m_minimize->setStyleSheet(QString("QToolButton{ border-image:url(%1); background:none;}" "QToolButton:hover{border-image:url(%2); background:none;}" "QToolButton::pressed{border-image:url(%3); background:none;}") .arg(strButtonMin).arg(strButtonMinOn).arg(strButtonMinSelected)); m_maxSheet = QString("QToolButton{ border-image:url(%1); background:none;}" "QToolButton:hover{border-image:url(%2); background:none;}" "QToolButton::pressed{border-image:url(%3); background:none;}") .arg(strButtonMax).arg(strButtonMaxOn).arg(strButtonMaxSelected); m_maximize->setStyleSheet(m_maxSheet); m_restoreStyleSheet = QString("QToolButton{ border-image:url(%1); background:none;}" "QToolButton:hover{border-image:url(%2); background:none;}" "QToolButton::pressed{border-image:url(%3); background:none;}") .arg(strButtonRestore).arg(strButtonRestoreOn).arg(strButtonRestoreSelected); m_close->setFixedSize(16, 16); m_minimize->setFixedSize(16, 16); m_maximize->setFixedSize(16, 16); m_titleLabel = new QLabel(this); m_titleLabel->setText(""); m_window->setWindowTitle(""); connect(m_close, SIGNAL( clicked() ), m_window, SLOT(close() ) ); connect(m_minimize, SIGNAL( clicked() ), this, SLOT(showSmall() ) ); connect(m_maximize, SIGNAL( clicked() ), this, SLOT(showMaxRestore() ) ); // setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); }