1、定义窗口类TestQt
TestQt的头文件TestQt.h
//TestQt.h
#pragma once
#include <QtWidgets/QMainWindow>
#include "ui_TestQt.h"
QT_BEGIN_NAMESPACE
namespace Ui { class TestQtClass; };
QT_END_NAMESPACE
class TestQt : public QMainWindow
{
Q_OBJECT
public:
TestQt(QWidget *parent = nullptr);
~TestQt();
private:
Ui::TestQtClass *ui;
};
TestQt的cpp文件TestQt.cpp
//TestQt.cpp
#include "TestQt.h"
TestQt::TestQt(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::TestQtClass())
{
ui->setupUi(this);
}
TestQt::~TestQt()
{
delete ui;
}
2、在主程序中调用窗口并设置窗口的显示状态
main.cpp文件
#include "TestQt.h"
#include <QtWidgets/QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
TestQt w;
w.show();
w.setWindowState(Qt::WindowMaximized); //设置窗口的状态
return a.exec();
}
3、窗口状态的枚举值
Qt::WindowNoState //窗口 正常显示
Qt::WindowMinimized //窗口 最小显示
Qt::WindowMaximized //窗口 最大显示
Qt::WindowFullScreen //窗口 填充整个屏幕,无边框
Qt::WindowActive //窗口 变为活动的窗口(如:可接受键盘输入)