09黑马QT笔记之坐标系统

09黑马QT笔记之坐标系统

1 先看结果:
可以看出,主窗口相对于屏幕,b1按钮相对于主窗口,b2即笑脸相对于按钮b1。

在这里插入图片描述
2: 代码实现:
1)项目文件:省略。
2)头文件:省略。
3).cpp文件:

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

MyWidget::MyWidget(QWidget *parent)
    : QWidget(parent)
{
    /*  this->move(0,0);
     1)相对于屏幕左上角而言的
     2)坐标原点为屏幕左上角
     3)x:往右递增
     4)y: 往左递增
    */
    this->move(0,0);
    resize(500,500);

    /*  b1->move(100,100);
     1)相对于主窗口空白部分左上角而言的(不包括边框)
     2)坐标原点为主窗口空白部分左上角
     3)x:往右递增
     4)y: 往左递增
    */
    QPushButton *b1=new QPushButton(this);
    b1->setText("你好");
    b1->move(100,100);
    b1->resize(200,100);

    /*  b2->move(10,10);
     1)相对于按钮1左上角而言的
     2)坐标原点为按钮1左上角
     3)x:往右递增
     4)y: 往左递增
    */
    QPushButton *b2=new QPushButton(b1);
    b2->setText("@_@");
    b2->move(10,10);
}

MyWidget::~MyWidget()
{

}

4)主函数:省略。

总结:这个例子理解起来比较简单。

发布了54 篇原创文章 · 获赞 1 · 访问量 688

猜你喜欢

转载自blog.csdn.net/weixin_44517656/article/details/105694183