开发者

update() or repaint() fails to trigger paintEvent()

开发者 https://www.devze.com 2022-12-20 03:09 出处:网络
I have a QScrollArea fathering my awesome scrolling widget. I like to do updates on the contents on various occasions.

I have a QScrollArea fathering my awesome scrolling widget. I like to do updates on the contents on various occasions.

For this I did an override of paintEvent(QPaintEvent *). Then everytime I want it to be done I call update() on the widget.

Problem: paintEvent() is never called by this!

What I tried in troubleshooting so far:

  • U开发者_StackOverflow中文版se repaint() instead of update(). Should call it instantanously. Unfortunately does not.
  • Test for isVisible() and updatesEnabled
  • Test wether my override is correct. Resizing the window calls my function. Only my manual update(), repaint() calls fail.
  • Implement a QTimer to trigger update() or repaint() every 500ms. The trigger gives text output, the function is not called.

Anybody got an idea what to check next? What could make repaint() not call paintEvent()?


The solution is to call this->viewport()->repaint() or this->viewport()->update() from your QAbstractScrollArea derived class instead of just repaint() or update().

More info is given in Qt documentation:

QWidget * QAbstractScrollArea::viewport () const

Returns the viewport widget. Use the QScrollArea::widget() function to retrieve the contents of the viewport widget.

Since the contents that we have in our QAbstractScrollArea derived class will be displayed in the viewport widget, makes sense to call viewport widget's update or repaint to draw our data again (have our paintEvent called).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号