// 父子关系--可以比较其他语言或框架中的容器子对象等 #include <QApplication> #include <QFont> #include <QPushButton> #include <QWidget> int main(int argc, char *argv[]) { QApplication app(argc, argv);//创建应用程序对象 QWidget window;//创建窗体对象 window.resize(200, 120);//设置大小 QPushButton quit("Quit", &window);//创建按钮,以上面的window对象作为父容器 quit.setFont(QFont("Times", 18, QFont::Bold)); quit.setGeometry(10, 40, 180, 40);//设置几何位置及尺寸,这里坐标(10,40)宽高(180,40) QObject::connect(&quit, SIGNAL(clicked()), &app, SLOT(quit())); window.show();//显示窗体 return app.exec(); } 截图: 本文转自 xcf007 51CTO博客,原文链接:http://blog.51cto.com/xcf007/103852,如需转载请自行联系原作者