自动关闭QMessageBox [英] Auto close QMessageBox

查看:514
本文介绍了自动关闭QMessageBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个Qt Symbian项目,我想向用户显示一条通知,该通知应在几秒钟后自动关闭.我已经看到诺基亚在用户界面中经常使用此功能.

I'm building a Qt Symbian Project and I want to show a notification for the user that should auto close after some seconds. I have seen that Nokia uses this a lot in their ui.

现在我正在使用下面的代码,以便用户可以关闭QMessageBox,但是如果可以在1或2秒后自动关闭QMessageBox,我希望这样做.如何使用Qt做到这一点?

Right now I'm using the code below so that the user can close the QMessageBox but I would like it if it was possible to auto close the QMessageBox after 1 or 2 seconds. How can I do this using Qt?

QMessageBox msgBox;
msgBox.setText("Hello!");
msgBox.setIcon(QMessageBox::Information);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.exec();

推荐答案

我建议将QMessageBox子类化,以添加自己想要的行为...

I would suggest to subclass QMessageBox to add your own desired behavior...

启用自动关闭选项后,添加setAutoClose(bool)setAutoCloseTimeout(int)之类的方法并在showEvent上触发QTimer会很有趣!

It would be interesting to add methods like setAutoClose(bool) and setAutoCloseTimeout(int) and trigger a QTimer on showEvent when the AutoClose option is enabled !

这样,您甚至可以更改QMessageBox的外观,并显示此框将在XXX秒后自动关闭..."或进度条等文字.

This way, you could even alter the apparence of your QMessageBox and had a text saying "This box will close automatically in XXX seconds..." or a progress bar, etc...

这篇关于自动关闭QMessageBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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