QRect Class
The QRect class defines a rectangle in the plane using integer precision. More...
Header: | #include <QRect> |
qmake: | QT += core |
Note: All functions in this class are reentrant.
Detailed Description
A rectangle is normally expressed as a top-left corner and a size. The size (width and height) of a QRect is always equivalent to the mathematical rectangle that forms the basis for its rendering.
A QRect can be constructed with a set of left, top, width and height integers, or from a QPoint and a QSize. The following code creates two identical rectangles.
QRect r1(100, 200, 11, 16);
QRect r2(QPoint(100, 200), QSize(11, 16));
QRect rectWinGeom;
rectWinGeom =this->geometry();
qDebug() <<" rectWinGeom ->geometry() :: "<< rectWinGeom; // 第 1次输出
rectWinGeom.setX(200);
rectWinGeom.setY(rectWinGeom.y()+50);
qDebug() <<" rectWinGeom ->geometry() :: "<< rectWinGeom; // 第 2次输出
rectWinGeom ->geometry() :: QRect(659,381 282x107) // 第 1次输出
rectWinGeom ->geometry() :: QRect(200,431 741x57) // 第 2次输出
QSize 类型
QT中使用size的函数得到的是QSize(100, 30)
https://blog.csdn.net/weixin_45394356/article/details/112853441
初始化使用size(),ui未使用show()
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
qDebug()<<ui->label->size();
qDebug()<<ui->tableWidget->size();
}
得到的是QSize(100, 30)、QSize(100, 30),这个是QT系统默认设置的。
但是调用show()或者是界面显示出来后,size()就会得到真实的值
————————————————
版权声明:本文为CSDN博主「一条傻闲鱼」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_45394356/article/details/112853441
QPoint 类型
https://zhidao.baidu.com/question/2273124190837383708.html
pos() //返回的是QPoint类型。定义一个QPoint对象来获取返回的值。
QPoint类有两个成员函数,分别是x()和y(),顾名思义这两个函数是用来获取QPoint表示位置的x和y坐标,这两个成员函数返回值都是int,所以你可以定义两个整型变量来保存它们的返回值。
这些在assistant中很容易就可以查到,善用assistant能解决大部分问题。