一.簡介
在項目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)