Qt equivalent of some Win32 code in OnMouseMove (mouseMoveEvent in Qt)
-
wrote on 5 Jul 2020, 11:36 last edited by
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() -
wrote on 5 Jul 2020, 17:00 last edited by
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 ?
-
wrote on 5 Jul 2020, 20:06 last edited by
I did look at it but at the time didn't think it would be relevant.
Right now I'm considering how much work it will be to work out how to only paint the invalidated region/rect versus the cost of just re-drawing the whole control.
D.
3/6