(二)widget部件的几何布局

空的Qt项目    main.cpp代码:

#include<QApplication>
#include<QWidget>
#include<QDebug>

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

    QWidget widget;
    widget.resize(400,300); //设置窗口大小
    widget.move(200,100);   //设置窗口位置
    widget.show();

    int x = widget.x();     //调试输出x的值
    qDebug("x:%d",x);
    int y = widget.y();
    qDebug("y:%d",y);
    QRect geometry = widget.geometry();
    QRect frame = widget.frameGeometry();
    qDebug()<<"geometry:"<<geometry<<"frame:"<<frame;

    return a.exec();
}

包含框架: x()   y()   frameGeometry()   pos()   move()

  xy为部件坐标,framegeometry为框架矩形值QRect类型,pos为在父窗口的位置,move为移动在父窗口里的位置

不包含框架:geometry()   width()   height()   rect()   size()

  geometry为部件矩形值QRect类型,width宽,heigeht高

调试输出: qDebug()    

原文地址:https://www.cnblogs.com/ZQHS/p/5686386.html