Qt 代码示例:创建简单窗口
#include <QtWidgets/QApplication> #include <QtWidgets/QWidget> #include <QtWidgets/QLabel>
int main(int argc, char *argv[]) { QApplication app(argc, argv);
QWidget window;
window.setWindowTitle('Hello, World!');
QLabel *label = new QLabel('Hello, World!', &window);
label->setAlignment(Qt::AlignCenter);
label->resize(200, 50);
window.resize(300, 150);
window.show();
return app.exec();
}
此代码创建一个名为'Hello, World!'的窗口,并在窗口中显示一个标签。标签中显示'Hello, World!'文本,并居中对齐。窗口大小设置为300x150,并显示在屏幕上。
AI 优化版
原文地址:https://www.cveoy.top/t/topic/nKQp 著作权归作者所有。请勿转载和采集!