You are not logged in.

1

Tuesday, May 12th 2015, 1:12pm

QMouseEvent , How to get two precision floating point of mouse position ? for example X=152.46 y=152.33 !

Hi all,
Actually, I have spent many many hours to get the answer but unfortunately I failed.

I know there is a QPointF class which contains the qreal value of mouse position. However, it does return the position with X.00 all the time. I mean it return the nearest integer.

void Widget::mouseMoveEvent(QMouseEvent *event)

{

qDebug()<<QString::number(event->localPos().x(), 'f', 2 );
qDebug()<<event->globalPos().x();
qDebug()<<event->globalX();
qDebug()<<event->pos().x();
qDebug()<<event->windowPos().x();

}


All these will return the nearest integer value for example
133.00 for the first one and 133 for the rest.

I need to get 133.17 or 132.89 for example not 133.00 or 133

All idea are appreciated.

Nai

2

Monday, May 18th 2015, 6:41pm

Hi,
Please have a look
http://blog.qt.io/blog/2015/05/11/integr…comment-1195852

Laszlo Agocs: "That depends on the platform in question. Many of them provide integer positions only for mouse events."

3

Monday, May 18th 2015, 6:47pm

However,
I have solved this issue by using QGraphicsItem to represent each pixel in its precision position and using mouseMoveEvent to get the floating precision position.