PDA

View Full Version : QMouseEvent->pos() gives different results for Qt-4.7.4 and Qt-5.11



sunburns
13th June 2018, 23:53
The attached code works fine on Centos 5 with Qt-4.7.4 and qwt-6.1.2. However, when I run on Centos 7 with Qt-5.11 and qwt-6.1.3, I get much different results. The std::cout where I print the x and y values of p_mouse_event->pos() look reasonable on Centos 5, but I get 0 for both x and y on Centos 7.

sunburns
13th October 2019, 19:50
I was able to fix this by changing the cast on line 56. Instead of casting to a QMouseEvent, I cast it to a QContextMenuEvent.

WRONG: const QMouseEvent *p_mouse_event = static_cast<QMouseEvent *>(p_event);
RIGHT: const QContextMenuEvent *p_mouse_event = static_cast<QContextMenuEvent *>(p_event);