qt_demoe/framelesswidget/frmframelesswidget.cpp

69 lines
1.8 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"
frmFramelessWidget::frmFramelessWidget(QWidget *parent) : QWidget(parent), ui(new Ui::frmFramelessWidget)
{
ui->setupUi(this);
}
frmFramelessWidget::~frmFramelessWidget()
{
delete ui;
}
2019-10-11 07:15:12 +00:00
void frmFramelessWidget::closeEvent(QCloseEvent *)
{
exit(0);
}
2019-10-10 05:42:12 +00:00
void frmFramelessWidget::on_btnOpen_clicked()
{
QWidget *w = new QWidget;
w->setAttribute(Qt::WA_DeleteOnClose);
2019-10-11 07:15:12 +00:00
w->setWindowFlags(Qt::WindowStaysOnTopHint);
2019-10-10 05:42:12 +00:00
w->setWindowTitle("自由拉伸无边框窗体");
2019-10-11 07:15:12 +00:00
w->setMinimumSize(200, 120);
2019-10-10 05:42:12 +00:00
w->resize(480, 320);
//设置下背景颜色区别看
QPalette palette = w->palette();
palette.setBrush(QPalette::Background, QColor(162, 121, 197));
w->setPalette(palette);
QPushButton *btn = new QPushButton(w);
btn->setText("关闭");
2019-10-11 07:15:12 +00:00
btn->setGeometry(10, 10, 130, 25);
connect(btn, SIGNAL(clicked(bool)), w, SLOT(close()));
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)));
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-10 05:42:12 +00:00
2019-10-11 07:15:12 +00:00
frameless = new FramelessWidget(w);
frameless->setWidget(w);
2019-10-10 05:42:12 +00:00
w->show();
}
2019-10-11 07:15:12 +00:00
void frmFramelessWidget::stateChanged1(int arg1)
{
frameless->setMoveEnable(arg1 != 0);
}
void frmFramelessWidget::stateChanged2(int arg1)
{
frameless->setResizeEnable(arg1 != 0);
}