pmofidi7469 | 2020-10-13 15:40:57 UTC | #1
Im trying to develop a program which have many of my custom widget. In my widget i have a crosshair mouse pointer and when i move it in one of my widgets all of them must sense it and the crosshair must react on every single widget.
I have a self.update() on the end of the paintEnent function. every thing seems good but a very huge CPU usage.
as you said ' If a widget is simple enough (like ours is) you can often get away with simply redrawing the entire thing any time anything happens. But for more complicated widgets this can get very inefficient. For these cases the paintEvent
includes the specific region that needs to be updated. We'll make use of this in later, more complicated examples.'
I have tried to do this but not successful. please make a good example.
martin | 2020-11-19 11:21:00 UTC | #2
Hey @pmofidi7469 welcome to the forum!
I have a self.update() on the end of the paintEnent function. every thing seems good but a very huge CPU usage.
If this is not a typo (mouseMoveEvent
maybe?) then this could be the source of the CPU usage. A paintEvent
is fired in response to .update()
being called, so calling in in your paintEvent
creates an effective infinite loop (though not quite, as updates can be ignored).
Purchasing Power Parity
Developers in [[ country ]] get [[ discount.discount_pc ]]% OFF on all books & courses with code [[ discount.coupon_code ]]The performance benefit of clipping with QPaintEvent.region()
is only in the drawing -- are you redrawing all the content of your other widgets? If you just need to move a cursor around on an otherwise unchanged image, you can cache the base image and then just redraw the cursor on top, for example.
If this doesn't make sense, can you post some code & I'll take a look!
pmofidi7469 | 2020-10-30 04:14:04 UTC | #3
I removed Update command from PaintEvent and i have used my custon Event to prevent updating all of region. Thnanks :)
PyQt6 Crash Course — a new tutorial in your Inbox every day
Beginner-focused crash course explaining the basics with hands-on examples.