Meate
31st July 2012, 19:56
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'?
void PaletteControl::mousePressEvent(QMouseEvent* evt)
{
mouseDown = true;
mouseStartPoint = evt->pos();
}
void PaletteControl::mouseMoveEvent(QMouseEvent* evt)
{
if (mouseDown) {
mouseDragging = true;
}
if (mouseDragging) {
QPoint newPoint = evt->pos();
int deltaX = newPoint.x() - mouseStartPoint.x();
int deltaY = newPoint.y() - mouseStartPoint.y();
QPoint pos = this->pos();
move(pos.x() + deltaX, pos.y() + deltaY);
update();
}
}
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'?
void PaletteControl::mousePressEvent(QMouseEvent* evt)
{
mouseDown = true;
mouseStartPoint = evt->pos();
}
void PaletteControl::mouseMoveEvent(QMouseEvent* evt)
{
if (mouseDown) {
mouseDragging = true;
}
if (mouseDragging) {
QPoint newPoint = evt->pos();
int deltaX = newPoint.x() - mouseStartPoint.x();
int deltaY = newPoint.y() - mouseStartPoint.y();
QPoint pos = this->pos();
move(pos.x() + deltaX, pos.y() + deltaY);
update();
}
}