Paint event may be triggered at any time by the underlying Qt drawing system. You should not assume that paint event can be triggered only by you. You need to change the logic in your app.
Qt paintEvent() unnormally triggered
-
10-06-2023 - |
Question
I'm a Qt beginner.
So I have my MainWindow with a QSlider
and a QPixmap
. I redefined the paintEvent( QPaintEvent* event )
and
connect( slider, SIGNAL(valueChanged(int)), this, SLOT(centerChange(int)) );
with a slot:
void MainWindow::centerChange(int value)
{
center = value;
update();
}
So I wanted repainte the Pixmap only if the slider's value is changed. But I notice that everytime when I make a mouse-in or a mouse-out to the slider, the repaint is triggered. Why is this happenning?
Thanks.
Solution
OTHER TIPS
The documentation says:
A paint event is a request to repaint all or part of a widget. It can happen for one of the following reasons:
- repaint() or update() was invoked,
- the widget was obscured and has now been uncovered, or
- many other reasons.
(emphasis mine). Specifically, the underlying OS could trigger a repaint event whenever it feels like.
Based on your requirements, don't reimplement paintEvent
then. Just do your QPixmap
updating when the slider value changed.