参考:
https://blog.csdn.net/GoForwardToStep/article/details/53494800
https://blog.csdn.net/liang19890820/article/details/50555298
上面两个链接是我查找到的两种实现自定义标题栏的方法,在实际应用的过程中觉得比较麻烦,而且标题栏效果不太好调整,所以我整理了下面的方法:
这里用的自定义标题栏就是一个普通的QWidget,实现了图标、最大化、最小化、关闭按钮以及拖动标题栏实现软件移动的功能。然后,取消系统的标题栏,换上自定义的标题栏就OK了,标题栏效果自己任意调整。
MainWindow的布局设置为verticalLayout,依次加入自定义标题栏、菜单栏、主功能界面。
setWindowFlags(Qt::FramelessWindowHint);
TitleBar *pTitleBar = new TitleBar(this);
pTitleBar->setWindowIcon(":/logo/logo.png", QSize(102, 41));
ui->verticalLayout->insertWidget(0, pTitleBar);
ui->verticalLayout->insertWidget(1, ui->menubar); //把菜单栏添加到自定义的标题栏下面
ui->menubar->setStyleSheet("background-color: transparent");
titlebar.h:
#ifndef TITLEBAR_H
#define TITLEBAR_H
#include <QWidget>
class QLabel;
class QPushButton;
class TitleBar : public QWidget
{
Q_OBJECT
public:
explicit TitleBar(QWidget *parent); //这里需要传入主窗口的指针,否则将无法实现拖动


8万+

被折叠的 条评论
为什么被折叠?



