当 QWidget::paintEvent() 悬停在其他窗口上时,如何强制调用 QWidget::paintEvent() ?
我有一个问题: 我正在创建一个显示当前日期的天数的小部件。它就像一个按钮,但它不是从 QPushButton
类派生的。刚刚来自 QWidget
。因此,我重新实现了 enterEvent()
、leaveEvent()
、mousePressEvent()
、mouseReleaseEvent()
。我确实在这些方法中调用 update()
,并且小部件具有真实的按钮行为(paintEvent()
也被重新实现)。 但是,当我更改系统日期并将该小部件悬停在其他窗口上时,我的小部件不会获取 paintEvent()
并显示旧日期。只有当我将鼠标放在它上面时,小部件才会重新绘制它的内容。 我猜想有一个功能(如缓冲)可以在与其他窗口悬停时绘制旧内容,以避免不必要的重新计算。但我需要禁用它。尝试设置许多属性(Qt::WidgetAttribute
枚举)。但这不起作用。
I have a problem:
I'm creating a widget which displays current date's day number. It's like a button, but it's not derived from QPushButton
class. Just from QWidget
. So I've reimplemented enterEvent()
, leaveEvent()
, mousePressEvent()
, mouseReleaseEvent()
. I do call update()
inside these methods and widget has realistic button behavior (paintEvent()
is reimplemented also).
But when I change system date and hover that widget with other window, my widget doesn't get paintEvent()
and the old date is displayed. Only when I place mouse over it, widget repaints it's contents.
I guess there is a feature (like buffering) which paints old contents on hovering with other window to avoid unnecessary recalculations. But I need to disable it. Tried to set many attributes (the Qt::WidgetAttribute
enum). But it doesn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您应该找到一种方法来检测系统时间已更改,并在发生更改时调用 update() 。任何其他方法(例如检测窗口的“悬停”或等待鼠标事件)都会导致更新发生得太晚。
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.