部件教程 - 创建窗口
如果创建的 Widget 没有父对象,那么在显示时就会被视为窗口或顶层 Widget。由于没有父对象来确保在不再需要时将其删除,因此开发人员需要跟踪应用程序中的顶层部件。
在下面的示例中,我们使用QWidget 创建并显示一个默认大小的窗口:
#include <QtWidgets> int main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget window; window.resize(320, 240); window.show(); window.setWindowTitle( QApplication::translate("toplevel", "Top-level widget")); return app.exec(); } | ![]() |
要创建真正的图形用户界面,我们需要在窗口中放置部件。为此,我们将向窗口部件的构造函数传递一个QWidget 实例,本教程的下一部分将对此进行演示。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.