控件座標系轉全局座標系
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