一.简介
在项目Application中:
QT Widgets Application(桌面QT应用)
QT Console Application(控制台QT应用)
QT for Python-Empty / Window(用Python开发QT应用)
QT Quick Application-Empty / Scroll / Stack /Swipe(移动平台开发QT应用)
1.Location
填一下项目名和项目地址
2.Kits
3.Details
类名(C):
基类(B):QMainWindow/QWidget/QDialog
头文件(H):
源文件(S):
创建界面(G):勾选
界面文件(F):
4.汇总
二.QMainWindow
三.QWidget
1.窗口框架
2.附加窗口
QWidget widget; widget.setWindowTitle(QObject::tr("k5")); widget.resize(400, 300); widget.move(200, 100); widget.show(); int x = widget.x(); qDebug("x:%d", x); int y = widget.y(); qDebug("y:%d", y);
四.QDialog
QDialog类继承与QWidget类
注意:添加hellodialog.ui文件的时候,要把里面的 <class>HelloDialog</class>
<widget class = "QDialog" name = "HelloDialog"> 改过来,不然会无法识别 ui 这个指针
1.窗口框架
// hellodialog.h #ifndef HELLODIALOG_H #define HELLODIALOG_H #include <QDialog> namespace Ui{ class HelloDialog; } class HelloDialog : public QDialog{ Q_OBJECT public: explicit HelloDialog(QWidget* parent = nullptr); ~HelloDialog(); private: Ui::HelloDialog* ui; }; #endif // HELLODIALOG_H
// hellodialog.cpp
#include "hellodialog.h" #include "ui_hellodialog.h" HelloDialog::HelloDialog(QWidget* parent) : QDialog(parent), ui(new Ui::HelloDialog) { ui->setupUi(this); } HelloDialog::~HelloDialog() { delete ui; }
// main.cpp #include "hellodialog.h" #include <QApplication> int main(int argc, char* argv[]) { QApplication a(argc, argv); HelloDialog w; w.show(); return a.exec(); }
2.附加窗口
(1)模态对话框
QDialog* dialog = new QDialog(this); dialog->setModal(true); dialog->show();
QDialog dialog;
dialog.setModal(true);
dialog.show()
(2)非模态对话框
QDialog* dialog = new QDialog(this); dialog->show(); QDialog dialog; dialog.show()
3.对话框状态
QDialog dialog; if (dialog.exec() == QDialog::Accepted)