1.项目文件
QT += widgets
SOURCES += \
main.cpp
2.主函数文件
#include <QApplication>
#include <QWidget>
#include <QPushButton>
int main(int argc, char *argv[])
{
QApplication app(argc,argv);
QWidget w;
w.setWindowTitle("Hello Qt5");
QPushButton b1;
// 指定父对象,有两种方式,setParent()和构造函数
b1.setParent(&w);
// 设置按钮内容
b1.setText("按钮1");
// 移动位置
b1.move(100,100);
QPushButton b2(&w);
b2.setText("按钮2");
b2.move(150,150);
w.show();
app.exec();
return 0;
}
效果如下