qt_demoe/framelesswidget/frmframelesswidget.cpp

101 lines
2.6 KiB
C++
Raw Normal View History

2019-10-10 05:42:12 +00:00
#pragma execution_character_set("utf-8")
#include "frmframelesswidget.h"
#include "ui_frmframelesswidget.h"
#include "qpushbutton.h"
2019-10-11 07:15:12 +00:00
#include "qcheckbox.h"
2019-10-10 05:42:12 +00:00
#include "framelesswidget.h"
2021-05-15 11:10:30 +00:00
#include "framelesswidget2.h"
2019-10-10 05:42:12 +00:00
frmFramelessWidget::frmFramelessWidget(QWidget *parent) : QWidget(parent), ui(new Ui::frmFramelessWidget)
{
ui->setupUi(this);
2021-05-15 11:10:30 +00:00
widget1 = 0;
frameless = 0;
2021-07-05 09:56:20 +00:00
frameless2 = 0;
2019-10-10 05:42:12 +00:00
}
frmFramelessWidget::~frmFramelessWidget()
{
delete ui;
}
2019-10-11 07:15:12 +00:00
void frmFramelessWidget::closeEvent(QCloseEvent *)
{
exit(0);
}
2021-05-15 11:10:30 +00:00
void frmFramelessWidget::initWidget(QWidget *w)
2019-10-10 05:42:12 +00:00
{
2021-05-15 11:10:30 +00:00
//设置无边框属性
w->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
//w->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
w->setWindowTitle("自由拉伸无边框窗体");
w->setMinimumSize(200, 120);
w->resize(480, 320);
2019-10-10 05:42:12 +00:00
2021-05-15 11:10:30 +00:00
//设置下背景颜色区别看
QPalette palette = w->palette();
2021-05-30 07:59:42 +00:00
palette.setBrush(QPalette::Window, QColor(162, 121, 197));
2021-05-15 11:10:30 +00:00
w->setPalette(palette);
2019-10-10 05:42:12 +00:00
2021-05-15 11:10:30 +00:00
QPushButton *btn = new QPushButton(w);
btn->setText("关闭");
btn->setGeometry(10, 10, 130, 25);
connect(btn, SIGNAL(clicked(bool)), w, SLOT(close()));
2019-10-11 07:15:12 +00:00
2021-05-15 11:10:30 +00:00
QCheckBox *cboxMove = new QCheckBox(w);
cboxMove->setText("可移动");
cboxMove->setChecked(true);
cboxMove->setGeometry(10, 40, 70, 25);
connect(cboxMove, SIGNAL(stateChanged(int)), this, SLOT(stateChanged1(int)));
2019-10-11 07:15:12 +00:00
2021-05-15 11:10:30 +00:00
QCheckBox *cboxResize = new QCheckBox(w);
cboxResize->setText("可拉伸");
cboxResize->setChecked(true);
cboxResize->setGeometry(80, 40, 70, 25);
connect(cboxResize, SIGNAL(stateChanged(int)), this, SLOT(stateChanged2(int)));
}
2019-10-11 09:13:42 +00:00
2021-05-15 11:10:30 +00:00
void frmFramelessWidget::on_pushButton_clicked()
{
if (widget1 == 0) {
widget1 = new QWidget;
this->initWidget(widget1);
frameless = new FramelessWidget(widget1);
frameless->setWidget(widget1);
2019-10-11 09:13:42 +00:00
}
2019-10-10 05:42:12 +00:00
2021-05-15 11:10:30 +00:00
widget1->show();
2019-10-10 05:42:12 +00:00
}
2019-10-11 07:15:12 +00:00
void frmFramelessWidget::stateChanged1(int arg1)
{
2021-05-15 11:10:30 +00:00
if (frameless != 0) {
frameless->setMoveEnable(arg1 != 0);
}
2021-07-05 09:56:20 +00:00
if (frameless2 != 0) {
frameless2->setMoveEnable(arg1 != 0);
}
2019-10-11 07:15:12 +00:00
}
void frmFramelessWidget::stateChanged2(int arg1)
{
2021-05-15 11:10:30 +00:00
if (frameless != 0) {
frameless->setResizeEnable(arg1 != 0);
}
2021-07-05 09:56:20 +00:00
if (frameless2 != 0) {
frameless2->setResizeEnable(arg1 != 0);
}
2021-05-15 11:10:30 +00:00
}
void frmFramelessWidget::on_pushButton_2_clicked()
{
2021-07-05 09:56:20 +00:00
if (frameless2 == 0) {
frameless2 = new FramelessWidget2;
this->initWidget(frameless2);
2021-05-15 11:10:30 +00:00
}
2021-07-05 09:56:20 +00:00
frameless2->show();
2019-10-11 07:15:12 +00:00
}