Qt equivalent of some Win32 code in OnMouseMove (mouseMoveEvent in Qt)
-
In the OnMouseMove() mf of a Win32 custom control which I am re-writing for Qt, there is some code that looks like this:
//----- Get the original erase area -----// getMarkerRgn(&oldrgn); //----- Draw the markers -----// : : getMarkerRgn(&newrgn); erasergn.CreateRectRgn(0,0,0,0); //Dummy rgn erasergn.CombineRgn(&oldrgn, &newrgn, RGN_DIFF); dc.FillRgn(&erasergn, &brush); // Background colour brush
The idea being to erase the previously drawn markers after the new ones are drawn
What should I be doing in Qt?
PS is there any Qt equivalent of the Windows OnEraseBackGround() ?
PPS only three weeks Qt experience so far so please be gentle!Many thanks
David -
Painting can only be done inside the paintEvent(): https://doc.qt.io/qt-5/paintsystem.html
The mouse move events can be captured with QWidget::mouseMoveEvent() -
So I can't paint inside the mouseMoveEvent() mf? Oh dear that's quite a problem.
What I'm doing is dragging a shape and as it is dragged the previously drawn version must be erased and the new one drawn which is what that code does (there's more to it than that but you get the idea).
So given that you seem to be saying "You can't get there from here" - how on earth do I handle this?
Thanks
David -
So I can't paint inside the mouseMoveEvent() mf? Oh dear that's quite a problem.
What I'm doing is dragging a shape and as it is dragged the previously drawn version must be erased and the new one drawn which is what that code does (there's more to it than that but you get the idea).
So given that you seem to be saying "You can't get there from here" - how on earth do I handle this?
Thanks
David@Perdrix
Hi
You just keep the shape rect / x,y as members of the class.
Then in MouseMove you alter its position and call update()
Then paintEvent is called it it draw the shapes in the pos.To erase the old shape, the code
// this you can do in mousePress Qt also has region https://doc.qt.io/qt-5/qregion.html
erasergn.CreateRectRgn(0,0,0,0); //Dummy rgn
erasergn.CombineRgn(&oldrgn, &newrgn, RGN_DIFF);// this goes to PaintEvent
dc.FillRgn(&erasergn, &brush); // Background colour brush
(change to use QPainter methods ofc) -
Hi,
Just a side question since you are mentioning a shape and movement, depending on what you want to do, did you consider the use of the Graphics View Framework ?