How to force calling of QWidget::paintEvent() when its hovered by other window?

帅比萌擦擦* 提交于 2020-01-30 13:15:10

问题


I have occured a problem: I'm writing 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 reimplemented enterEvent(), leaveEvent(), mousePressEvent(), mouseReleaseEvent(). I call update() inside these methods and widget has realistic button behavior (paintEvent() is reimplemented too). 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.

Please, help me (and sorry for my bad english).


回答1:


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.



来源:https://stackoverflow.com/questions/4703219/how-to-force-calling-of-qwidgetpaintevent-when-its-hovered-by-other-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!