Widget dragging, widget doesn't fully draw
I created a widget that I can drag around the window. As the widget is being dragged, part of it doesn't draw fully, especially when dragging at faster speeds.
For example, while dragging the widget to the left, the left few pixels of the widget don't get drawn.
It's acting as if the widget is getting moved, but is clipped on the edge in the direction of the movement. This is a very simple widget and so moving/drawing it should be pretty quick (it's just a colored rectangle).
Basically, I'm just capturing a mousePressEvent, and then dragging the widget using move() based on the new mouse position in the mouseMoveEvent. I've tried various combinations of repaints and updates, but they don't seem to make any difference.
Any suggestions on how to make this more 'snappy'?
Code:
{
mouseDown = true;
mouseStartPoint = evt->pos();
}
{
if (mouseDown) {
mouseDragging = true;
}
if (mouseDragging) {
int deltaX = newPoint.x() - mouseStartPoint.x();
int deltaY = newPoint.y() - mouseStartPoint.y();
move(pos.x() + deltaX, pos.y() + deltaY);
update();
}
}
Re: Widget dragging, widget doesn't fully draw
use graphics view which will do this for you.
Re: Widget dragging, widget doesn't fully draw
amleto, thank you for the suggestion. In fact, my widget eventually will contain controls and will be dragged around the QMainWindow, and so using the graphics view doesn't work for my purposes. I tried using a QDockWidget, but it has some undesired behaviors.
Added after 1 55 minutes:
I think I figured it out. It seems the parent widget needs to be told to update itself when one of its children is moved (outside of a layout). Calling parentWidget()->update() after the move() fixes the drawing issue.