qt_demoe/widget/framelesswidget/framelessform/dialog.cpp

70 lines
1.7 KiB
C++
Raw Normal View History

2021-07-27 07:35:23 +00:00
#include "dialog.h"
#include "ui_dialog.h"
2021-09-16 06:48:38 +00:00
#pragma execution_character_set("utf-8")
2021-07-27 07:35:23 +00:00
Dialog::Dialog(QWidget *parent) : FramelessDialog(parent), ui(new Ui::Dialog)
{
ui->setupUi(this);
this->initForm();
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::initForm()
{
//设置标题栏控件
ui->labTitle->setText("无边框窗体示例-支持win、linux、mac等系统 (QQ: 517216493 WX: feiyangqingyun)");
this->setWindowTitle(ui->labTitle->text());
this->setTitleBar(ui->labTitle);
//关联信号
connect(this, SIGNAL(titleDblClick()), this, SLOT(titleDblClick()));
connect(this, SIGNAL(windowStateChange(bool)), this, SLOT(windowStateChange(bool)));
//设置样式表
QStringList list;
list << "#titleBar{background:#BBBBBB;}";
list << "#titleBar{border-top-left-radius:8px;border-top-right-radius:8px;}";
list << "#widgetMain{border:2px solid #BBBBBB;background:#FFFFFF;}";
//list << "#widgetMain{border-bottom-left-radius:8px;border-bottom-right-radius:8px;}";
this->setStyleSheet(list.join(""));
}
void Dialog::titleDblClick()
{
on_btnMenu_Max_clicked();
}
void Dialog::windowStateChange(bool max)
{
ui->btnMenu_Max->setText(max ? "还原" : "最大");
}
void Dialog::on_btnMenu_Min_clicked()
{
#ifdef Q_OS_MACOS
this->setWindowFlags(this->windowFlags() & ~Qt::FramelessWindowHint);
#endif
this->showMinimized();
}
void Dialog::on_btnMenu_Max_clicked()
{
if (this->isMaximized()) {
this->showNormal();
ui->btnMenu_Max->setText("最大");
} else {
this->showMaximized();
ui->btnMenu_Max->setText("还原");
}
}
void Dialog::on_btnMenu_Close_clicked()
{
this->close();
}