改进代码

This commit is contained in:
feiyangqingyun
2021-09-19 17:37:01 +08:00
parent e500c225ab
commit e1065dd361
7 changed files with 76 additions and 43 deletions

View File

@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<widget class="FramelessDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
@@ -210,6 +210,14 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>FramelessDialog</class>
<extends>QWidget</extends>
<header>framelessdialog.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@@ -6,14 +6,22 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>207</width>
<height>59</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0">
<property name="spacing">
<number>0</number>
@@ -212,6 +220,14 @@
</layout>
</widget>
</widget>
<customwidgets>
<customwidget>
<class>FramelessMainWindow</class>
<extends>QWidget</extends>
<header>framelessmainwindow.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Widget</class>
<widget class="QWidget" name="Widget">
<widget class="FramelessWidget" name="Widget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
@@ -210,6 +210,14 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>FramelessWidget</class>
<extends>QWidget</extends>
<header>framelesswidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@@ -4,16 +4,19 @@
#include "ui_frmframelesswidget.h"
#include "qpushbutton.h"
#include "qcheckbox.h"
#include "qdebug.h"
#include "framelesswidget2.h"
#ifndef Q_CC_MSVC
#include "framelessform/dialog.h"
#include "framelessform/widget.h"
#include "framelessform/mainwindow.h"
#endif
frmFramelessWidget::frmFramelessWidget(QWidget *parent) : QWidget(parent), ui(new Ui::frmFramelessWidget)
{
ui->setupUi(this);
widget = 0;
frameless = 0;
this->initForm();
}
frmFramelessWidget::~frmFramelessWidget()
@@ -21,9 +24,14 @@ frmFramelessWidget::~frmFramelessWidget()
delete ui;
}
void frmFramelessWidget::closeEvent(QCloseEvent *)
void frmFramelessWidget::initForm()
{
exit(0);
widget = 0;
frameless = 0;
connect(ui->btnDialog, SIGNAL(clicked(bool)), this, SLOT(buttonClicked()));
connect(ui->btnWidget, SIGNAL(clicked(bool)), this, SLOT(buttonClicked()));
connect(ui->btnMainWindow, SIGNAL(clicked(bool)), this, SLOT(buttonClicked()));
}
void frmFramelessWidget::initWidget(QWidget *w)
@@ -84,23 +92,19 @@ void frmFramelessWidget::stateChanged2(int arg1)
}
}
void frmFramelessWidget::on_btnDialog_clicked()
void frmFramelessWidget::buttonClicked()
{
Dialog dialog;
dialog.resize(800, 600);
dialog.exec();
}
void frmFramelessWidget::on_btnWidget_clicked()
{
Widget *widget = new Widget;
widget->resize(800, 600);
widget->show();
}
void frmFramelessWidget::on_btnMainWindow_clicked()
{
MainWindow *window = new MainWindow;
window->resize(800, 600);
window->show();
#ifndef Q_CC_MSVC
QString objName = sender()->objectName();
if (objName == "btnDialog") {
Dialog dialog;
dialog.exec();
} else if (objName == "btnWidget") {
Widget *widget = new Widget;
widget->show();
} else if (objName == "btnMainWindow") {
MainWindow *window = new MainWindow;
window->show();
}
#endif
}

View File

@@ -16,23 +16,18 @@ public:
explicit frmFramelessWidget(QWidget *parent = 0);
~frmFramelessWidget();
protected:
void closeEvent(QCloseEvent *);
private:
Ui::frmFramelessWidget *ui;
QWidget *widget;
FramelessWidget2 *frameless;
private slots:
void initForm();
void initWidget(QWidget *w);
void on_pushButton_clicked();
void stateChanged1(int arg1);
void stateChanged2(int arg1);
void on_btnDialog_clicked();
void on_btnWidget_clicked();
void on_btnMainWindow_clicked();
void buttonClicked();
};
#endif // FRMFRAMELESSWIDGET_H