一.简介
1.Location
2.Kits
3.Details
4.汇总
二.QMainWindow
三.QWidget
1.窗口框架
2.附加窗口
QWidget widget;
widget.setWindowTitle(QObject::tr("k5"));
widget.resize(, );
widget.move(, );
widget.show();
int x = widget.x();
qDebug("x:%d", x);
int y = widget.y();
qDebug("y:%d", y);
四.QDialog
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)