日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

qt 自定义标题栏

發(fā)布時間:2025/3/15 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 qt 自定义标题栏 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

TitleBar.h

#ifndef TITLE_BAR #define TITLE_BAR#include <QWidget>class QLabel; class QPushButton;class TitleBar : public QWidget {Q_OBJECTpublic:explicit TitleBar(QWidget *parent = 0);~TitleBar();protected:// 雙擊標題欄進行界面的最大化/還原virtual void mouseDoubleClickEvent(QMouseEvent *event);// 進行鼠界面的拖動virtual void mousePressEvent(QMouseEvent *event);// 設置界面標題與圖標virtual bool eventFilter(QObject *obj, QEvent *event);private slots:// 進行最小化、最大化/還原、關閉操作void onClicked();private:// 最大化/還原void updateMaximize();private:QLabel *m_pIconLabel;QLabel *m_pTitleLabel;QPushButton *m_pMinimizeButton;QPushButton *m_pMaximizeButton;QPushButton *m_pCloseButton; };#endif // TITLE_BAR

TitleBar.cpp

#include <QLabel> #include <QPushButton> #include <QHBoxLayout> #include <QEvent> #include <QMouseEvent> #include <QApplication> #include "TitleBar.h"#ifdef Q_OS_WIN #pragma comment(lib, "user32.lib") #include <qt_windows.h> #endifTitleBar::TitleBar(QWidget *parent): QWidget(parent) {setFixedHeight(30);m_pIconLabel = new QLabel(this);m_pTitleLabel = new QLabel(this);m_pMinimizeButton = new QPushButton(this);m_pMaximizeButton = new QPushButton(this);m_pCloseButton = new QPushButton(this);m_pIconLabel->setFixedSize(20, 20);m_pIconLabel->setScaledContents(true);m_pTitleLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);m_pMinimizeButton->setFixedSize(27, 22);m_pMaximizeButton->setFixedSize(27, 22);m_pCloseButton->setFixedSize(27, 22);m_pTitleLabel->setObjectName("whiteLabel");m_pMinimizeButton->setObjectName("minimizeButton");m_pMaximizeButton->setObjectName("maximizeButton");m_pCloseButton->setObjectName("closeButton");m_pMinimizeButton->setToolTip("Minimize");m_pMaximizeButton->setToolTip("Maximize");m_pCloseButton->setToolTip("Close");QHBoxLayout *pLayout = new QHBoxLayout(this);pLayout->addWidget(m_pIconLabel);pLayout->addSpacing(5);pLayout->addWidget(m_pTitleLabel);pLayout->addWidget(m_pMinimizeButton);pLayout->addWidget(m_pMaximizeButton);pLayout->addWidget(m_pCloseButton);pLayout->setSpacing(0);pLayout->setContentsMargins(5, 0, 5, 0);setLayout(pLayout);connect(m_pMinimizeButton, SIGNAL(clicked(bool)), this, SLOT(onClicked()));connect(m_pMaximizeButton, SIGNAL(clicked(bool)), this, SLOT(onClicked()));connect(m_pCloseButton, SIGNAL(clicked(bool)), this, SLOT(onClicked())); }TitleBar::~TitleBar() {}void TitleBar::mouseDoubleClickEvent(QMouseEvent *event) {Q_UNUSED(event);emit m_pMaximizeButton->clicked(); }void TitleBar::mousePressEvent(QMouseEvent *event) { #ifdef Q_OS_WINif (ReleaseCapture()){QWidget *pWindow = this->window();if (pWindow->isTopLevel()){SendMessage(HWND(pWindow->winId()), WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);}}event->ignore(); #else #endif }bool TitleBar::eventFilter(QObject *obj, QEvent *event) {switch (event->type()){case QEvent::WindowTitleChange:{QWidget *pWidget = qobject_cast<QWidget *>(obj);if (pWidget){m_pTitleLabel->setText(pWidget->windowTitle());return true;}}case QEvent::WindowIconChange:{QWidget *pWidget = qobject_cast<QWidget *>(obj);if (pWidget){QIcon icon = pWidget->windowIcon();m_pIconLabel->setPixmap(icon.pixmap(m_pIconLabel->size()));return true;}}case QEvent::WindowStateChange:case QEvent::Resize:updateMaximize();return true;}return QWidget::eventFilter(obj, event); }void TitleBar::onClicked() {QPushButton *pButton = qobject_cast<QPushButton *>(sender());QWidget *pWindow = this->window();if (pWindow->isTopLevel()){if (pButton == m_pMinimizeButton){pWindow->showMinimized();}else if (pButton == m_pMaximizeButton){pWindow->isMaximized() ? pWindow->showNormal() : pWindow->showMaximized();}else if (pButton == m_pCloseButton){pWindow->close();}} }void TitleBar::updateMaximize() {QWidget *pWindow = this->window();if (pWindow->isTopLevel()){bool bMaximize = pWindow->isMaximized();if (bMaximize){m_pMaximizeButton->setToolTip(tr("Restore"));m_pMaximizeButton->setProperty("maximizeProperty", "restore");}else{m_pMaximizeButton->setProperty("maximizeProperty", "maximize");m_pMaximizeButton->setToolTip(tr("Maximize"));}m_pMaximizeButton->setStyle(QApplication::style());} }


widget.h

#ifndef __WIDGET__ #define __WIDGET__ #include "TitleBar.h" #include <QDialog> #include <QWidget> #include <QVBoxLayout>class Widget :public QWidget { public:Widget(QWidget* parent = 0);~Widget(); private:TitleBar *m_pTitleBar;QVBoxLayout *m_pLayout; };#endif


widget.cpp

#include "Widget.h" #include <QIcon> #include <QDir> #include <QCoreApplication>Widget::Widget(QWidget* parent) :QWidget(parent), m_pTitleBar(NULL), m_pLayout(NULL) {setWindowFlags(Qt::FramelessWindowHint);m_pTitleBar = new TitleBar(this);installEventFilter(m_pTitleBar);resize(400, 300);setWindowTitle("Custom Window");QDir::setCurrent(QCoreApplication::applicationDirPath());QString strLanPath = QObject::tr("%1\\skin\\public\\title.png").arg(QDir::currentPath());strLanPath = QDir::toNativeSeparators(strLanPath);setWindowIcon(QIcon(strLanPath));QPalette pal(palette());pal.setColor(QPalette::Background, QColor(50, 50, 50));setAutoFillBackground(true);setPalette(pal);m_pLayout = new QVBoxLayout();m_pLayout->addWidget(m_pTitleBar);m_pLayout->addStretch();m_pLayout->setSpacing(0);m_pLayout->setContentsMargins(0, 0, 0, 0);setLayout(m_pLayout); }Widget::~Widget() {delete(m_pLayout);delete(m_pTitleBar); } style.qss
QPushButton#closeButton {background:transparent url(skin/public/close.png) no-repeat center center;border:none;width:20px;height:20px; } QPushButton#closeButton:hover {background:transparent url(skin/public/close_hover.png) no-repeat center center; } QPushButton#closeButton:pressed {background:transparent url(skin/public/close_pressed.png) no-repeat center center; } QPushButton#closeButton:disabled {background:transparent url(skin/public/close_disabled.png) no-repeat center center; }QPushButton#maximizeButton {background:transparent url(skin/public/max.png) no-repeat center center;border:none;width:20px;height:20px; } QPushButton#maximizeButton:hover {background:transparent url(skin/public/max_hover.png) no-repeat center center; } QPushButton#maximizeButton:pressed {background:transparent url(skin/public/max_pressed.png) no-repeat center center; } QPushButton#maximizeButton:disabled {background:transparent url(skin/public/max_disabled.png) no-repeat center center; }QPushButton#minimizeButton {background:transparent url(skin/public/min.png) no-repeat center center;border:none;width:20px;height:20px; } QPushButton#minimizeButton:hover {background:transparent url(skin/public/min_hover.png) no-repeat center center; } QPushButton#minimizeButton:pressed {background:transparent url(skin/public/min_pressed.png) no-repeat center center; } QPushButton#minimizeButton:disabled {background:transparent url(skin/public/min_disabled.png) no-repeat center center; }


總結

以上是生活随笔為你收集整理的qt 自定义标题栏的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 最近中文字幕在线免费观看 | 五月婷婷六月综合 | 国产99久久久国产精品免费看 | 欧美激情aaa | 成人激情免费 | 特黄特色大片免费播放器使用方法 | 99re6这里只有精品 | 女同av在线 | 精品久操 | 天堂资源在线 | 亚洲国产一区二区在线 | 日韩综合中文字幕 | 国产在线123 | www.婷婷| 亚洲第一伊人 | 91一区二区三区四区 | 97成人资源 | 中文字幕乱码一区二区三区 | 成年人在线播放 | 91亚洲精华国产精华精华液 | mm131丰满少妇人体欣赏图 | juliaann精品艳妇hd | 久草五月天| 国产xxxx18| 老司机综合网 | 91精品国产综合久久久久久 | 黄色av网站在线看 | 精品国产乱码久久久久久久 | 日韩av不卡电影 | 岛国片在线免费观看 | 伊人网国产 | 久久国产秒 | 色婷婷婷婷| 国产黄网在线观看 | 亚洲第一av网站 | 清冷学长被爆c躁到高潮失禁 | 国产吃瓜黑料一区二区 | 色姑娘综合网 | a级片免费播放 | 国产任你操 | 伊人精品视频 | 色婷婷av一区二区三区之e本道 | 免费性视频 | 69式视频| 亚洲欧美另类视频 | xxx视频在线观看 | 日韩欧美一区二区三区在线观看 | 日韩两性视频 | 九九九九九伊人 | 4虎最新网址 | 国产www视频 | 污污视频网站在线免费观看 | 伊人视屏 | 法国空姐在线观看完整版 | 99热在线这里只有精品 | 河北彩花av在线播放 | 国产网站在线 | 老司机一区二区三区 | 美美女高清毛片视频免费观看 | 久久精品视频中文字幕 | 成人av在线播放网站 | 欧美xxxxbbb| 国产精品久久久久久久久免费相片 | 亚洲色婷婷久久精品av蜜桃 | 久热欧美 | 男人午夜免费视频 | 美女主播福利视频 | 久久精品国产99久久久 | 欧美精产国品一二三区 | www.久久国产 | 国产又粗又长又黄视频 | 色偷偷888欧美精品久久久 | 嫩草午夜少妇在线影视 | 日韩你懂的 | 欧美日韩视频网站 | 国产视频123区 | 天堂999 | 日韩精品一区二区三 | 在办公室被c到呻吟的动态图 | 麻豆传媒在线视频 | 自拍偷拍亚洲图片 | 99色亚洲 | 日本中文字幕一区二区 | 欧美人与性动交α欧美精品 | 亚洲天堂影院在线观看 | 邻居少妇张开双腿让我爽一夜 | 新亚洲天堂 | 人妻少妇精品视频一区二区三区 | 伊人网综合在线 | www.久热 | 香蕉视频污视频 | 男人的天堂avav | 福利在线免费观看 | 午夜精品福利一区二区 | 少妇被又大又粗又爽毛片久久黑人 | 男人和女人日批视频 | 色综合久久久久无码专区 | 亚洲视频在线视频 | 亚洲性免费 |