码迷,mamicode.com
首页 > 其他好文 > 详细

QT 定时执行某个函数,隐藏某个控件

时间:2018-07-13 19:04:09      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:minimum   timer   定时器   styles   tst   span   class   get   geo   

  1. QTimer::singleShot(3000, this, SLOT(slotHideFinishedLabel())); // 这里是一个3秒定时器, 且只执行一次。

#include "dialog.h" #include "ui_dialog.h" #include <QLabel> #include <QTimer> Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog), label(new QLabel(this)) { ui->setupUi(this); } Dialog::~Dialog() { delete ui; } void Dialog::on_toolButton_clicked() { showFinished(); QTimer::singleShot(3000, this, SLOT(slotHideFinishedLabel())); // 这里是一个3秒定时器, 且只执行一次。 } //下面这是提示框隐藏 void Dialog::slotHideFinishedLabel() { label->hide(); this->close(); } //下面这个红色提示框显示 void Dialog::showFinished() { QRect rect = geometry(); label->setMaximumWidth(500); label->setMaximumHeight(50); label->setMinimumWidth(500); label->setMinimumHeight(50); QFont font; font.setPointSize(25); label->setFont(font); label->setStyleSheet(QLatin1String("color:red;")); label->setText("The answer end of time!"); label->setGeometry(int((rect.width()-label->width())/2), int((rect.height()-label->height())/2), label->width(), label->height()); label->show();

  

QT 定时执行某个函数,隐藏某个控件

标签:minimum   timer   定时器   styles   tst   span   class   get   geo   

原文地址:https://www.cnblogs.com/wangjian8888/p/9306499.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!