geometry() : " <<_qwidget::move">
赞
踩
move设置位置但是不能到正确设置,但是用setGeometry是可以的
move设置位置是(0 , 0),但是实际位置为(10,42)
- void fixSizeWidget::on_pushButton_clicked()
- {
- QRect rect = QRect(0 , 0 , 1028 , 720);
- qDebug() << Q_FUNC_INFO << __LINE__ << "this->geometry() : " << this->geometry();
- qDebug() << Q_FUNC_INFO << __LINE__ << "rect.topLeft()" << rect.topLeft();
- this->move(rect.topLeft());
- qDebug() << Q_FUNC_INFO << __LINE__ << "this->geometry() : " << this->geometry();
- qDebug() << Q_FUNC_INFO << __LINE__ << "rect.topLeft()" << rect.topLeft();
- this->setFixedSize( 1028 , 720);
- qDebug() << Q_FUNC_INFO << __LINE__ << "this->geometry() : " << this->geometry();
- qDebug() << Q_FUNC_INFO << __LINE__ << "rect.topLeft()" << rect.topLeft();
-
- this->setGeometry(rect);
- qDebug() << Q_FUNC_INFO << __LINE__ << "this->geometry() : " << this->geometry();
- }
打印的信息
void fixSizeWidget::on_pushButton_clicked() 20 this->geometry() : QRect(760,362 400x300)
void fixSizeWidget::on_pushButton_clicked() 21 rect.topLeft() QPoint(0,0)
void fixSizeWidget::on_pushButton_clicked() 23 this->geometry() : QRect(10,42 400x300)
void fixSizeWidget::on_pushButton_clicked() 24 rect.topLeft() QPoint(0,0)
void fixSizeWidget::on_pushButton_clicked() 26 this->geometry() : QRect(10,42 1028x720)
void fixSizeWidget::on_pushButton_clicked() 27 rect.topLeft() QPoint(0,0)
void fixSizeWidget::on_pushButton_clicked() 30 this->geometry() : QRect(0,0 1028x720)
找到原因了,因为使用move的时候会包括边框的偏移,move的官方文档
If the widget is a window, the position is that of the widget on the desktop, including its frame.
而setGeometry不包括边框,setGeometry的官方文档
This property holds the geometry of the widget relative to its parent and excluding the window frame
这里所说的边框是frameGeometry和Geometry之间,如下图所示
文献参考:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。