日韩性视频-久久久蜜桃-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在线免费观看视频 | 性xxxx欧美 | 午夜视频在线观看国产 | 欧美一区二区区 | 国产欧美日韩久久 | 米奇狠狠干| 琪琪久久 | 日本成人在线播放 | 婷婷麻豆| 国产精品偷乱一区二区三区 | 婷婷精品一区二区三区 | 精品久久久久一区 | 毛片看 | av爱爱爱| 中文字幕成人一区 | 强乱中文字幕av一区乱码 | 国产av一区二区三区 | 香蕉黄色网| 欧美 日韩 国产 成人 在线 | 日本免费网站在线观看 | 免费在线观看a视频 | 国产精品午夜影院 | 欧美日韩午夜爽爽 | 可以免费观看av的网站 | 尤果网福利视频在线观看 | 黄色网炮| 成人91在线 | 国产婷婷一区二区 | 成人h动漫精品一区 | 日本黄色小说 | 中文字幕在线二区 | 亚洲 欧美 中文字幕 | 女同毛片一区二区三区 | 欧美精品成人一区二区三区四区 | 网红福利视频 | 国产69精品麻豆 | 国产99在线 | 亚洲 | 亚洲精品v | 超碰夜夜 | 少妇视频在线观看 | 老狼影院伦理片 | 少妇2做爰交换朴银狐 | 麻豆免费观看视频 | 日韩伦理av | 国产人与禽zoz0性伦 | 热久久中文字幕 | 中文字幕在线观看国产 | 长篇高h乱肉辣文 | 欧美黄色录像 | 国产人成精品 | 久久国产精品国语对白 | 丁香六月五月婷婷 | 日韩欧美一区二区三区四区 | 成全影视在线观看第8季 | 日韩电影一区二区三区四区 | 久久久久久久久久99精品 | 91视频xxx | 国产又色又爽又黄的 | 午夜精品久久久 | 国产123区在线观看 91国产一区二区 | 少妇第一次交换又紧又爽 | 精品人妻一区二区三区四区在线 | 欧美人与禽zozzo性之恋的特点 | 国精产品一区二区 | 东京热一本视频一区 | 久草视频在线资源 | 黄色av电影网址 | 女王人厕视频2ⅴk | 成人动漫一区二区三区 | 成人羞羞国产免费游戏 | 亚洲综合色视频 | 一二三区在线视频 | 深夜成人福利视频 | 日本精品视频一区 | 69精品国产| 亚洲欧美日韩一区二区三区在线观看 | 麻豆国产一区二区三区四区 | 久久精品综合视频 | 日韩高清一区二区 | www三级免费| 一区免费 | 国产激情视频一区二区 | 美日韩免费 | 日本高清视频在线观看 | 好姑娘在线观看高清完整版电影 | 午夜影院| 国产欧美一区二区精品性色 | 中文字幕第八页 | 国产伦精品一区二区三区四区 | 黄色国产小视频 | 毛片xxx | 国产精品一区二区三区久久久 | 毛片在线观看网站 | av电影在线观看网址 | 亚洲射色 | 一本一道久久 | 欧美理论视频 |