在创建Qt Gui Application时,总会让你选择在QWidget,QMainWindow和QDialog中选择一个Base Class。
这三个类具体有什么区别呢?在Qt的手册和网上找了一些资料。
先看官方的手册:
QWidget Class Reference
The QWidget class is the base class of all user interface objects.
Inherits: QObject and QPaintDevice.
Inherited by: ……, QDialog, ……,QMainWindow, ……
QDialog Class Reference
The QDialog class is the base class of dialog windows.
Inherits: QWidget.
QMainWindow Class Reference
The QMainWindow class provides a main application window.
Inherits: QWidget.
可以看到QMainWindow和QDialog都是继承自QWidget。再看看下面那段从网上转过来的介绍,大概就能了解三者之间的区别了。

本文介绍了Qt编程中常见的三种窗口类:QWidget、QMainWindow和QDialog。QWidget是所有用户界面对象的基础,QMainWindow用于构建带有菜单栏、工具栏和状态栏的主应用窗口,而QDialog则常用于短期任务的对话框窗口,可设置为模式或非模式。理解三者间的区别对于创建合适的用户界面至关重要。
最低0.47元/天 解锁文章
3262





