• 大小: 1.2MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-08-09
  • 语言: 其他
  • 标签: Qt  可移动  

资源简介

QWidget及其子类窗体组件的标题栏受操作系统的控制,即标题栏的界面风格与操作系统的主题风格相同,工程实践中需要开发者自行定义,达到美化应用程序界面的目的。开发环境是Qt5.7,调试成功,可自行下载,如有问题请留言,谢谢!

资源截图

代码片段和文件信息

#include “customtitlewidget.h“
#include “ui_customtitlewidget.h“

CustomtitleWidget::CustomtitleWidget(QWidget *parent) :
    QWidget(parent)
    ui(new Ui::CustomtitleWidget)
{
    ui->setupUi(this);

    ui->label->setSizePolicy(QSizePolicy::Expanding QSizePolicy::Fixed);

    ui->maxBtn->setToolTip(tr(“最小化“));
    ui->minBtn->setToolTip(tr(“最大化“));
    ui->closeBtn->setToolTip(tr(“关闭“));



    connect(ui->maxBtn SIGNAL(clicked(bool)) this SLOT(slotClicked()));
    connect(ui->minBtn SIGNAL(clicked(bool)) this SLOT(slotClicked()));
    connect(ui->closeBtn SIGNAL(clicked(bool)) this SLOT(slotClicked()));
}

CustomtitleWidget::~CustomtitleWidget()
{
    delete ui;
}

void CustomtitleWidget::updateMaximize()
{
    QWidget *pWindow = this->window();
    if (pWindow->isTopLevel())
    {
        bool bMaximize = pWindow->isMaximized();
        if (bMaximize)
        {
            ui->maxBtn->setToolTip(tr(“Restore“));
            ui->maxBtn->setProperty(“maximizeProperty“ “restore“);
        }
        else
        {
            ui->minBtn->setProperty(“maximizeProperty“ “maximize“);
            ui->minBtn->setToolTip(tr(“Maximize“));
        }

        ui->maxBtn->setstyle(QApplication::style());
    }
}

void CustomtitleWidget::mouseDoubleClickEvent(QMouseEvent *event)
{
    Q_UNUSED(event);

    emit ui->maxBtn->clicked();
}

void CustomtitleWidget::mousePressEvent(QMouseEvent *event)
{
    if (ReleaseCapture())
    {
        QWidget *pWindow = this->window();
        if (pWindow->isTopLevel())
        {
            SendMessage(HWND(pWindow->winId()) WM_SYSCOMMAND SC_MOVE + HTCAPTION 0);
        }
    }
    event->ignore();
}

void CustomtitleWidget::slotClicked()
{
    QPushButton *pButton = qobject_cast(sender());
    QWidget *pWindow = this->window();
    if (pWindow->isTopLevel())
    {
        if (pButton == ui->minBtn)
        {
            pWindow->showMinimized();
        }
        else if (pButton == ui->maxBtn)
        {
            pWindow->isMaximized() ? pWindow->showNormal() : pWindow->showMaximized();
        }
        else if (pButton == ui->closeBtn)
        {
            pWindow->close();
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-01-21 14:30  QttitleWidget\
     文件         726  2019-01-21 10:58  QttitleWidget\.qmake.stash
     文件        2297  2019-01-21 11:01  QttitleWidget\customtitlewidget.cpp
     文件         872  2019-01-21 10:47  QttitleWidget\customtitlewidget.h
     文件        4535  2019-01-21 11:06  QttitleWidget\customtitlewidget.ui
     目录           0  2019-01-21 11:01  QttitleWidget\debug\
     文件      563214  2019-01-21 11:01  QttitleWidget\debug\customtitlewidget.o
     文件      517548  2019-01-21 11:01  QttitleWidget\debug\main.o
     文件        3633  2019-01-21 11:01  QttitleWidget\debug\moc_customtitlewidget.cpp
     文件      328195  2019-01-21 11:01  QttitleWidget\debug\moc_customtitlewidget.o
     文件        9895  2019-01-21 11:01  QttitleWidget\debug\moc_predefs.h
     文件        2689  2019-01-21 11:01  QttitleWidget\debug\moc_widget.cpp
     文件      306678  2019-01-21 11:01  QttitleWidget\debug\moc_widget.o
     文件     2114582  2019-01-21 11:01  QttitleWidget\debug\QttitleWidget.exe
     文件      535443  2019-01-21 11:01  QttitleWidget\debug\widget.o
     文件         175  2019-01-21 10:43  QttitleWidget\main.cpp
     文件       26364  2019-01-21 11:01  QttitleWidget\Makefile
     文件       56623  2019-01-21 11:01  QttitleWidget\Makefile.Debug
     文件       56739  2019-01-21 11:01  QttitleWidget\Makefile.Release
     文件        1087  2019-01-21 10:44  QttitleWidget\QttitleWidget.pro
     文件       14406  2019-01-21 14:30  QttitleWidget\QttitleWidget.pro.user
     目录           0  2019-01-21 10:52  QttitleWidget\release\
     文件        5001  2019-01-21 11:01  QttitleWidget\ui_customtitlewidget.h
     文件         671  2019-01-21 11:06  QttitleWidget\widget.cpp
     文件         284  2019-01-21 10:51  QttitleWidget\widget.h

评论

共有 条评论