QT学习之父窗口

#include "mainwindow.h"
#include <QApplication>
#include <QWidget>
#include <qdialog.h>
#include <QLabel>
#include <QPushButton>
#include <QMainWindow>

int main(int argc, char *argv[])
{
    QApplication app(argc,argv);

    //QWidget parent;
    QDialog parent;//栈对象
    //QMainWindow parent;

    parent.move(50,50);
    parent.resize(320,240);

    //创建标签控件,停靠在父窗口上面
    QLabel label("我是标签",&parent);
    label.move(20,40);//创建按钮控件,停靠在父窗口上面


    QPushButton button("我是按钮",&parent);
    button.move(20,80);
    button.resize(80,80);

    //在堆区创建控件对象,如果指定了父窗口指针,可以不写delete,在父窗口对象销毁时,它会自动销毁
    QPushButton* button2 = new QPushButton("我是按钮",&parent);
    button2->move(170,100);
    button2->resize(80,80);

    parent.show();//父窗口显示,上面停靠的控件也一起显示

    //delete button2;//用不着
    return app.exec();
}

猜你喜欢

转载自blog.csdn.net/weiabc/article/details/121456767