When is paintevent called qt




















There are some exceptions, through QPaintEvent::erased you can know whether the widget is erased. Repaint the widget directly by calling paintEvent immediately. If erase is true, Qt erases the area x,y,w,h before calling paintEvent. If w is negative, it is replaced by width -x, and if h is negative, it is replaced by height -y. If you need to repaint immediately, it is recommended to use repaint , such as during an animation. In most cases, update is better because it allows Qt to optimize speed and prevent flicker.

Warning: If you call repaint in a function and it itself is called by paintEvent , you may see a wireless loop.

The update function never generates a loop. But when I change system date and hover that widget with other window, my widget doesn't calls paintEvent and displays old date. Only when I place mouse over it, widget repaints it's contents. I guess there is an option, which paints old contents on hover event to avoid unnecessary paint events. But I need to disable it. Tried to set many attributes Qt::WidgetAttribute enum.

But it doesn't helps. I think you should find a way to detect that the system time has changed and call update when that happens. Any other method like detecting the "hovering" of a window or waiting for a mouse event will cause the update to occur too late.

I had a similar problem where I wanted to paint on a toplevel widget and have only the painted part appear. If you have any problems with the registration process or your account login, please contact us.

Remember Me? Results 1 to 4 of 4. Thread: Calling paintEvent when I want to. Thread Tools Show Printable Version. Calling paintEvent when I want to I have a paintEvent function. Not only is this a potential optimization over having each application redraw itself, it also allows the DWM to implement things like Aero Flip, for which it uses its cached bitmap. If the bitmap that the DWM has cached has become invalidated e. Test this theory by turning off DWM composition switching to the "Windows Classic" theme , and then obscuring your window to see if you receive a paint event.

You should, just like you did in all previous versions of Windows. But the larger point is that you should not rely on receiving paint events in any particular order. The only thing you should assume about paint events is that you'll receive one when the operating system needs you to repaint your window. Otherwise, it won't bother you. I'm sure that's why the documentation is content with being vague on this point, beyond possible technical constraints. This is why logic should not go inside of the paint event handler.

The only thing that method should be responsible for is repainting the window by its current state. That state needs to saved elsewhere. This rule is also commutative: you should not do any painting outside of the paint event handler. Of course, you can always force a paint event to be raised by invalidating your window I'm sure Qt has an invalidate or refresh method for this, check the documentation , but that still doesn't mean it's a good pattern to place application logic in the method that handles this event.

Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?



0コメント

  • 1000 / 1000