QWidget move problem in QT 5.6
I'm working on a QT based GIS app. It was written with QT 4.8.4 and I ported all the app in QT 5.5 a few month ago and now I'm using QT 5.6 for the LTS.
I'm still using the old QGLWidget, and there is no plan to start using the new QOpenGLWidget.
I have some problem with thoses widgets. When a few of them are opened and when I try to move one of them around, QT send moveEvent with incorrect positions. Even with dragging my widget in the middle of the app with smooth and small circle, I can see my widget teleporting all around. In debug I often end up with negative values for the moveEvent when i'm obviously not supposed to get them.
After a few try, I can always reproduce it with QT 5.6.2, but not in QT 5.5, and it only happens when the widget is not dockable.
I wasn't able to find anythings related in the QT bug tracker, and being new in the QT community I don't really know what to do with this, but it's really annoying.
What am I supposed to do know ? Open a tracker ? Is it a known issue ? I lack the english words to be able to search for it efficiently.
Thanks for your help.
If its possible to create a
small sample that displays this behavior
then please open up a bug report so it can be tested.
I've got a bit further on this topic.
Thanks to the QT doc, I was able to resolve a part of the problem !
The QMouseEvent Class page say this : "The functions pos(), x(), and y() give the cursor position relative to the widget that receives the mouse event. If you move the widget as a result of the mouse event, use the global position returned by globalPos() to avoid a shaking motion."
My reimplementation of the mouseMoveEvent code of the titlebar was indeed using pos() instead of globalPos(). It's fixed now.
But my problem is not over. I still have this shaking motion problem with the resize, and only if I resize from the left border.
I know that :
- I got a shaking while resizing when the resize need a move first
- My window inherit from QMdiSubWindow
- There is no custom code in that event chain, all is from QT
- QMdiSubWindow::mouseMoveEvent is calling this for the resize :
Why isn't it using mouseEvent->globalPos() as stated in the doc ?
I really need some help, I'm stuck here. I've this bug while it's Qt only, but I can make a minimal example to reproduce it, while I can see in the code that something is (maybe) wrong.
Thanks for your help !
Why isn't it using mouseEvent->globalPos() as stated in the doc ? (QMdiSubWindow::mouseMoveEvent)
Because the all child's x,y are relative to parent.
so to move it inside QMdi Parent, then you need to map from local x,y to
the Parent x,y as else it would be relative to 0,0 (global) and
would not work. x,y would be wrong.
You mean this tip fro mthe doc
If you move the widget as a result of the mouse event, use the global position returned by globalPos() to avoid a shaking motion.
does not apply to QMdiSubWindow ?
Here is what I understand from my problem.
When I resize, I got a few event from the mouse. In some case, resize + repaint can take some time, so it can happend that a mouseEvent is send and stacked before the previous is correctly processed.
It means that my mouseEvent is send before moving my widget and processed after it's moved, and as it use mouseEvent->pos, and relative coordinate, thoses coords are wrong, because the 0,0 moved, and it cause a odds shaking effect.
Using globalPos, prevent this because the origin never move, and I can use QWidget::mapFromGlobal to translate my globalPos to what pos() should really be.
So if i'm right, QMdiSubWindow should somethings like parent->mapFromglobal(mouseEvent->globalPos() to avoid that shaking effect.
I guess I'm wrong somewhere, but I can't see where.