QT学习第六篇

1.主要内容为坐标系统和空间释放问题

#include "mywidget.h"
#include <QPushButton>
#include "mybutton.h"

MyWidget::MyWidget(QWidget *parent)
    : QWidget(parent)
{
    /* 对于父窗口(主窗口),坐标系统相对于屏幕
     * 原点:相对于屏幕左上角
     * x: 往右递增
     * y: 往下递增
    */
    move(100, 100);


    /* 子窗口,坐标系统相对于父窗口
     * 原点:相对于窗口空白区域左上角(不包括边框)
     * x: 往右递增
     * y: 往下递增
    */
    QPushButton *b1 = new QPushButton(this);
    b1->move(100, 100);
    b1->setText("^_^");
    b1->resize(200, 100);

    QPushButton *b2 = new QPushButton(b1);

    b2->move(10, 10);
    b2->setText("@_@");


    MyButton *b3 = new MyButton(this);
    b3->setText("123");

    //1)指定父对象后  2)直接或间接继承于QObject
    //子对象如果是动态分配空间的new,不需要手动释放delete
    //系统会自动释放

}

MyWidget::~MyWidget()
{

}
 

发布了36 篇原创文章 · 获赞 7 · 访问量 7794

猜你喜欢

转载自blog.csdn.net/qq_33301482/article/details/103246810
今日推荐