1、坐标系统
- 定位类型
— 顶级窗口部件的定位
— 窗口内部件的定位
— 窗口部件的大小设置
2、QWidget 类中的坐标系统成员函数(跨平台)
— x() //边框的起始点横坐标
— y() //边框的起始点纵坐标
— width() //客户区终点的横坐标
— height() //客户区终点的纵坐标
— geometry() //客户区(中间灰色区域)
x(), y(), width(), height()
— frameGeometry() //边框
x(), y(), width(), height()
注意事项:geometry()
和 frameGeometry()
中的几何数据必须在 show()
调用后才有效。
resize()
函数对应 width()
和 height()
的数值
move()
函数对应 x()
和 y()
的数值
#include "Widget.h"
#include "QDebug"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.move(100,100);
w.resize(400,300);
w.show();
qDebug() << "QWidget::";
qDebug() << w.x();
qDebug() << w.y();
qDebug() << w.width();
qDebug() << w.height() << endl;
qDebug() << "QWidget::geometry";
qDebug() << w.geometry().x();
qDebug() << w.geometry().y();
qDebug() << w.geometry().width();
qDebug() << w.geometry().height() << endl;
qDebug() << "QWidget::frameGeometry";
qDebug() << w.frameGeometry().x();
qDebug() << w.frameGeometry().y();
qDebug() << w.frameGeometry().width();
qDebug() << w.frameGeometry().height() << endl;
return a.exec();
}
resize()
函数对应的是客户区(灰色区域) width()
和 height()
的数值,并非边框。
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
QPushButton btn1(&w);
btn1.setText("Button");
btn1.move(50, 50);
btn1.resize(100, 30);
QPushButton btn2(&w);
btn2.setText("Button");
btn2.move(200, 50);
btn2.resize(100, 30);
w.setWindowTitle("计算器");
w.move(10, 10);
w.setFixedSize(500, 500);
w.show();
}
Button 的基准定位是基于整个客户区(灰色区域)。