Qt无边框窗口

无边框窗口

/**
 * 自定义无边框窗体、对话框和提示框
 *
 * MainWindow.h
 * 测试用例主要窗口
 *
 */

#include <QLabel>
#include <QDebug>
#include "MainWindow.h"
#include "ui_MainWindow.h"
#include "ui_AeroClientWidget.h"
#include "MuWinWindow.h"

MainWindow::MainWindow(QWidget *parent)
    : MuCustomWindow(parent)
    , ui(new Ui::MainWindow)
    , aeroUI(new Ui::AeroCLientWidget)
{
    setWindowTitle("Test Custom Window");
    resize(800, 600);

    QWidget *pClientWidget = new QWidget(this);
    ui->setupUi(pClientWidget);

    this->titleBar()->setTitleHeight(50);
    this->titleBar()->setObjectName("titleBar");
    this->titleBar()->titleLabel()->setObjectName("titleLabel");
    this->titleBar()->minimizeButton()->setObjectName("minimizeButton");
    this->titleBar()->maximizeButton()->setObjectName("maximizeButton");
    this->titleBar()->closeButton()->setObjectName("closeButton");

    // 设置中心客户区域
    setClientWidget(pClientWidget);

    // 设置messagebox的按钮样式表和标题样式表
    const QString buttonStyle = "QPushButton {  \
                                    border: none; \
                                    background-color: #52baff; \
                                    width: 80px; \
                                    height: 30px; \
                                 } \
                                 QPushButton::pressed { \
                                    background-color: gray; \
                                 }";
    MuCustomMessageBox::setTitleStyleSheet(QStringLiteral("QLabel { color: black }"));
    MuCustomMessageBox::setButtonStyleSheet(QDialogButtonBox::Ok, buttonStyle);
    connect(ui->dialogBtn, &QPushButton::clicked, this, &MainWindow::onDialogBtnClicked);
    connect(ui->informationBtn, &QPushButton::clicked, this, &MainWindow::onInformationBtnClicked);
    connect(ui->errorBtn, &QPushButton::clicked, this, &MainWindow::onErrorBtnClicked);
    connect(ui->successBtn, &QPushButton::clicked, this, &MainWindow::onSuccessBtnClicked);
    connect(ui->warningBtn, &QPushButton::clicked, this, &MainWindow::onWarningBtnClicked);
#ifdef Q_OS_WIN32
    initAreoWindow();
    connect(ui->aeroBtn, &QPushButton::clicked, m_AeroWindow, &MuWinAeroShadowWindow::show);
    connect(ui->winWindowBtn, &QPushButton::clicked, this, &MainWindow::onWinWindow);
#else
    ui->aeroBtn->hide();
#endif
}

MainWindow::~MainWindow()
{
    delete ui;
#ifdef Q_OS_WIN32
    delete m_AeroWindow;
#endif
}

void MainWindow::onDialogBtnClicked()
{
    MuCustomDialog dialog;
    QLabel label("This is a Custom Dialog!");
    label.setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
    dialog.titleBar()->titleLabel()->setObjectName("dialogTitleLabel");
    dialog.setModal(true);
    dialog.setWindowTitle("dialog");
    dialog.setClientWidget(&label);
    dialog.exec();
}

void MainWindow::onInformationBtnClicked()
{
    MuCustomMessageBox::showInformation(nullptr,
                                        QStringLiteral("Information!"),
                                        QStringLiteral("This is a Information MessageBox!"));
}

void MainWindow::onErrorBtnClicked()
{
    MuCustomMessageBox::showError(nullptr,
                                  QStringLiteral("Error!"),
                                  QStringLiteral("This is a Error MessageBox!"));
}

void MainWindow::onSuccessBtnClicked()
{
    MuCustomMessageBox::showSuccess(nullptr,
                                    QStringLiteral("Success!"),
                                    QStringLiteral("This is a Success MessageBox!"));
}

void MainWindow::onWarningBtnClicked()
{
    MuCustomMessageBox::showWarning(nullptr,
                                    QStringLiteral("Warning!"),
                                    QStringLiteral("This is a Warning MessageBox!"));
}

#ifdef Q_OS_WIN32
void MainWindow::initAreoWindow()
{
    m_AeroWindow = new MuWinAeroShadowWindow;
    m_AeroWindow->setRubberBandOnMove(true);
    m_AeroWindow->setRubberBandOnResize(true);
    m_AeroWindow->setWindowTitle(QStringLiteral("Test Aero Window"));
    m_AeroWindow->titleBar()->setObjectName("aeroTitleBar");
    QWidget *pClientWidget = new QWidget(m_AeroWindow);
    aeroUI->setupUi(pClientWidget);
    m_AeroWindow->setClientWidget(pClientWidget);
}
#endif

void MainWindow::onWinWindow()
{
    MuWinWindow *window = new MuWinWindow;
    window->resize(800, 600);
    window->show();
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值