当 QWidget::paintEvent() 被其他窗口悬停时,如何强制调用它? [英] How to force calling of QWidget::paintEvent() when its hovered by other window?

查看:46
本文介绍了当 QWidget::paintEvent() 被其他窗口悬停时,如何强制调用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题:我正在编写一个小部件,它显示当前日期的天数.它就像一个按钮,但它不是从 QPushButton 类派生的.仅来自 QWidget.所以我重新实现了enterEvent()leaveEvent()mousePressEvent()mouseReleaseEvent().我在这些方法中调用 update() 并且小部件具有逼真的按钮行为(paintEvent() 也重新实现).但是当我更改系统日期并将该小部件悬停在其他窗口时,我的小部件不会调用 paintEvent() 并显示旧日期.只有当我将鼠标放在它上面时,小部件才会重新绘制它的内容.我想有一个选项,它在悬停事件上绘制旧内容以避免不必要的绘制事件.但我需要禁用它.试图设置许多属性(Qt::WidgetAttribute 枚举).但这无济于事.

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

推荐答案

我认为您应该找到一种方法来检测系统时间已更改并在发生这种情况时调用 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.

这篇关于当 QWidget::paintEvent() 被其他窗口悬停时,如何强制调用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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