您的位置:首页 > 编程语言 > Qt开发

QT 实现在一个模块中间显示一个红色提示框,3秒后消失

2016-01-31 16:36 597 查看
#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();
}

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: