QMessageBox 使用方法
来源:互联网 发布:天策雪河军爷捏脸数据 编辑:程序博客网 时间:2024/06/05 20:59
QMessageBox普通用法
静态函数街口,直接调用,缺点是不太灵活,无法设置窗口风格
void about ( QWidget * parent, const QString & title, const QString & text )void aboutQt ( QWidget * parent, const QString & title = QString() )StandardButton critical ( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton )StandardButton information ( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton )StandardButton question ( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton )StandardButton warning ( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton )
例子:
int ret = QMessageBox::warning(this, tr("My Application"), tr("The document has been modified.\n" "Do you want to save your changes?"), QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save); //使用标准按键时可以利用 exec()函数的返回值,判断用户选择 switch (ret) { case QMessageBox::Save: // Save was clicked break; case QMessageBox::Discard: // Don't Save was clicked break; case QMessageBox::Cancel: // Cancel was clicked break; default: // should never be reached break; }
QMessageBox 高级用法
有时需要自定义按键的文本,窗口关闭后需要判断用户点击的按键,代码如下:
QMessageBox msgBox(this);//保证窗口居中//设置无标题栏 msgBox.setWindowFlags( PreOrNext.windowFlags() |Qt::FramelessWindowHint); msgBox.setIcon(QMessageBox::Question); msgBox.setText(tr("xxxxxxxxx?")); QPushButton *btnNxt = msgBox.addButton(tr("确定"),QMessageBox::AcceptRole); QPushButton *btnPre = msgBox.addButton(tr("取消"),QMessageBox::RejectRole); msgBox.setDefaultButton(btnNxt); PreOrNext.exec(); //阻塞等待用户选则(模态窗口) if (msgBox.clickedButton() == btnNxt ) { // connect } else if (msgBox.clickedButton() == btnPre ) { // abort }
阅读全文
0 0
- QMessageBox 使用方法
- QMessageBox
- QMessageBox
- QMessageBox
- QMessageBox
- QMessageBox
- QMessageBox
- QMessageBox
- QMessageBox
- QMessageBox
- QMessageBox
- QMessageBox
- QMessageBox
- QMessageBox
- QMessageBox
- QMessageBox
- QT的QMessageBox使用方法(设置字体大小,颜色等)
- QMessageBox解析
- 序列化和反序列化BST
- 基于maven的S2SH(Struts2+Spring+Hibernate)的框架DEMO
- 关于px、rem、em的区别
- 静态方法加锁,和非静态方法加锁区别
- nyoj 289苹果 01背包
- QMessageBox 使用方法
- Redis性能问题排查解决手册
- Entity Framework Core 2.0 新特性
- zoj-3721(贪心)
- 栈地址分配
- 爬虫闯关——2
- 利用servlet去动态的导出一个Excel表格
- 2138-图结构练习——BFSDFS——判断可达性
- 深度学习中对 end2end的理解