版权声明:转载请注明出处 https://blog.csdn.net/understand125/article/details/54313527
控件坐标系转全局坐标系
QPoint QWidget::mapToGlobal ( const QPoint &pos ) const
例:
源码:
QLineEdit lineEdit;
lineEdit.setGeometry(100, 100, 200, 100);
qDebug() << “Widget: ” << lineEdit.rect().topLeft();
qDebug() << "Global: " << lineEdit.mapToGlobal( lineEdit.rect().topLeft());
执行结果:
全局坐标系转控件坐标系
QPoint QWidget::mapFromGlobal ( const QPoint &pos ) const
例:
源码:
QWidget w;
QLineEdit lineEdit(&w);
lineEdit.setGeometry(100,100,200,25);
QPoint pos(50,50);
pos = w.mapFromGlobal(pos);
lineEdit.move(pos);
w.show();
执行结果:
控件坐标系转父控件坐标系
QPoint QWidget::mapTo ( QWidget *parent, const QPoint &pos ) const // parent 不能为0
or
QPoint QWidget::mapToParent ( const QPoint &pos ) const // 当无父控件时,同 mapToGlobal
父控件坐标系转为控件坐标系
QPoint QWidget::mapFrom ( QWidget *parent, const QPoint &pos ) const // parent 不能为0
or
QPoint QWidget::mapFromParent ( const QPoint &pos) const // 当无父控件时,同 mapToGlobal