自定义程序等待提示框

在读取文件或者某一次操作需要一段耗时,我们可以在主程序添加等待提示框,提示用户正在操作,请稍候

思路是,使用QDialog 设置setWindowFlags属性为Qt::FramelessWindowHint无边框

然后在dialog上添加一个QLabel

在需要的地方exec()

操作结束就调用accept()关闭提示框

.h文件

 QDialog dialog;
 QLabel labinfo;

.cpp文件

构造函数中

 dialog.setWindowFlags(Qt::FramelessWindowHint| Qt::Dialog | Qt::WindowTitleHint);
 dialog.setWindowTitle("Title");
 QHBoxLayout *layout = new QHBoxLayout;//QGridLayout
 layout->addWidget(&labinfo);
 dialog.setLayout(layout);//可以设置背景色rgb(153,204,51)

在需要的地方调用

//处理耗时操作
labinfo.setText(QString::fromLocal8Bit("正在操作,请稍候......"));
dialog.exec();

处理结束后

dialog.accept();

 

 

效果图如下

 


版权声明:本文为zzxfbdfhbdfhbdb原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。