我想让我QWidget
在图像上显示光标的坐标,我读到最好的方法是使用QLineEdit
,但我没有找到如何使用它。如何启动QLineEdit
以及如何显示它,以便它跟随光标?PS:我知道如何在上面设置点坐标。这就是我的做法:
void QImageWidget::mouseMoveEvent( QMouseEvent *event ){
int x = event->pos( ).x();
int y = event->pos( ).y();
if( cursorLineEdit != NULL && cursorLineEdit->isEnabled( ) )
cursorLineEdit->setText( QString( "[ %1 , %2 ]" ).arg( x ).arg( y ) );
}
mouseTracking 已经设置为 true :
this->setMouseTracking(true);
谢谢 !
编辑: cursorLineEdit 是我要显示的 QLineEdit,我需要在我的 QWidget 构造函数上初始化它,但我不知道如何!