update() 或 repaint() 无法触发paintEvent() [英] update() or repaint() fails to trigger paintEvent()

查看:246
本文介绍了update() 或 repaint() 无法触发paintEvent()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 QScrollArea 是我很棒的滚动小部件的父亲.我喜欢在各种场合更新内容.

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

为此,我覆盖了paintEvent(QPaintEvent *).然后每次我想要完成它时,我都会在小部件上调用 update().

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

问题: paintEvent() 永远不会被这个调用!

Problem: paintEvent() is never called by this!

到目前为止我在故障排除中的尝试:

What I tried in troubleshooting so far:

  • 使用 repaint() 而不是 update().应该立即调用它.不幸的是没有.
  • 测试 isVisible()updatesEnabled
  • 测试我的覆盖是否正确.调整窗口大小会调用我的函数.只有我的手动 update()、repaint() 调用失败.
  • 实现一个 QTimer 以每 500 毫秒触发一次 update() 或 repaint().触发器给出文本输出,不调用函数.
  • Use 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.

有人知道接下来要检查什么吗?什么可以使 repaint() 调用paintEvent()?

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

推荐答案

解决方案是调用this->viewport()->repaint()this->viewport()->update() 来自您的 QAbstractScrollArea 派生类,而不仅仅是 repaint()update().

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

Qt 文档中提供了更多信息:

QWidget * QAbstractScrollArea::viewport() const

返回视口小部件.使用 QScrollArea::widget() 函数来检索视口小部件的内容.

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

由于我们在 QAbstractScrollArea 派生类中的内容将显示在视口小部件中,因此调用视口小部件的更新或重新绘制以再次绘制我们的数据是有意义的(让我们的 paintEvent 调用).

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).

这篇关于update() 或 repaint() 无法触发paintEvent()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆