概述
无边框窗口
/**
* 自定义无边框窗体、对话框和提示框
*
* 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();
}
最后
以上就是虚拟朋友为你收集整理的Qt无边框窗口的全部内容,希望文章能够帮你解决Qt无边框窗口所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复