• 大小: 2KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-20
  • 语言: 其他
  • 标签: Qt  menuBar  

资源简介

Qt 自定义软件标题栏 -- 复用菜单栏menuBar(); .h文件和.cpp文件,不是可直接编译使用的. 参见:https://blog.csdn.net/zwb0540822/article/details/106072615

资源截图

代码片段和文件信息

#include “mywindowtitlebar.h“
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#include 
#include 

MyWindowtitleBar::MyWindowtitleBar(QWidget * parent QString appIcon):Qframe(parent)
    mainLayout(NULL)
    addIcon(NULL)
    menu(NULL)
    titleLable(NULL)
    minButton(NULL)
    maxButton(NULL)
    closeButton(NULL)
    bMax(false)
{
    setupUi();

    addIcon->setPixmap(QIcon(appIcon).pixmap(2424));

    connect(minButtonSIGNAL(clicked())thisSLOT(OnMinButton()));
    connect(maxButtonSIGNAL(clicked())thisSLOT(OnMaxButton()));
    connect(closeButtonSIGNAL(clicked())thisSLOT(OnCloseButton()));
}

void MyWindowtitleBar::setupUi()
{
    mainLayout = new QHBoxLayout(this);
    mainLayout->setContentsMargins(51102);
    mainLayout->setSpacing(10);

    addIcon = new QLabel(this);

    minButton = new QToolButton(this);
    minButton->setIcon(QIcon(“:/images/min.png“));
    minButton->setAutoRaise(true);
    minButton->setstyleSheet(“QToolButton:hover{background-color:blue;}“);
    minButton->setIconSize(QSize(4022));

    maxButton = new QToolButton(this);
    maxButton->setIcon(QIcon(“:/images/max.png“));
    maxButton->setAutoRaise(true);
    maxButton->setstyleSheet(“QToolButton:hover{background-color:blue;}“);
    maxButton->setIconSize(QSize(4022));

    closeButton = new QToolButton(this);
    closeButton->setIcon(QIcon(“:/images/close.png“));
    closeButton->setAutoRaise(true);
    closeButton->setstyleSheet(“QToolButton:hover{background-color:red;}“);
    closeButton->setIconSize(QSize(4022));

    QSpacerItem *horizontalSpacer1;
    QSpacerItem *horizontalSpacer2;
    horizontalSpacer1 = new QSpacerItem(40 20 QSizePolicy::Expanding QSizePolicy::Minimum);
    horizontalSpacer2 = new QSpacerItem(40 20 QSizePolicy::Expanding QSizePolicy::Minimum);

    titleLable = new QLabel(this);
    titleLable->setText(“title“);
    titleLable->setSizePolicy(QSizePolicy::Expanding QSizePolicy::Minimum);

    titleLayout = new QHBoxLayout();
    titleLayout->addItem(horizontalSpacer1);
    titleLayout->addWidget(titleLable);
    titleLayout->addItem(horizontalSpacer2);


    this->setAutoFillBackground(true);
    QPalette ss = this->palette();
    ss.setColor(QPalette::Window Qt::white);
    this->setPalette(ss);
}

void MyWindowtitleBar::SetMainMenuBar(QMenuBar *parentM QString appIcon)
{
    if (parentM==NULL)
        return ;

    mainLayout->removeWidget(addIcon);
    mainLayout->removeWidget(menu);
    mainLayout->removeItem(titleLayout);
    mainLayout->removeWidget(minButton);
    mainLayout->removeWidget(maxButton);
    mainLayout->removeWidget(closeButton);


    addIcon->setPixmap(QIcon(appIcon).pixmap(2424));

    mainLayout->addWidget(addIcon);

    mainLayout->addWidget(parentM)

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       1104  2020-08-05 18:40  mywindowtitlebar.h

     文件       6638  2020-08-05 18:40  mywindowtitlebar.cpp

----------- ---------  ---------- -----  ----

                 7742                    2


评论

共有 条评论