控件坐标系转全局坐标系
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(po

本文介绍了QT中的坐标转换,包括从全局坐标系到控件坐标系的转换,控件坐标系到父控件坐标系的转换,以及父控件坐标系回转到控件坐标系的方法,通过具体的代码示例进行解析。
最低0.47元/天 解锁文章
2094

被折叠的 条评论
为什么被折叠?



