Qt msgBox 快捷版
生活随笔
收集整理的這篇文章主要介紹了
Qt msgBox 快捷版
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
使用
1 int iRet = msgBox(pos, tr("警告") 2 , tr("確定要刪除當前選中的行嗎?") 3 , tr("確定"), tr("取消"), 1, 1); 4 if (1 == iRet) return; // 0:確定 1:取消
?
?
實現
1 //在指定的點topLeft 顯示 MessageBox 2 int msgBox(const QPoint& topLeft 3 , const QString &title 4 , const QString &text 5 , const QString &button0 6 , const QString &button1 7 , const int &defaultButton 8 , const int &escapeButton 9 , QMessageBox::Icon icon 10 , QWidget *parent) 11 { 12 QMessageBox msg(icon, title, text, QMessageBox::NoButton, parent 13 , Qt::WindowStaysOnTopHint | Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint); 14 15 QPushButton* pBtn0 = NULL; 16 QPushButton* pBtn1 = NULL; 17 18 pBtn0 = msg.addButton(button0, QMessageBox::NoRole); //id = 0 19 if (!button1.isEmpty()) 20 { 21 pBtn1 = msg.addButton(button1, QMessageBox::NoRole); //id = 1 22 } 23 24 if (defaultButton == 0) msg.setDefaultButton(pBtn0); 25 if (!button1.isEmpty()) 26 { 27 if (defaultButton == 1) msg.setDefaultButton(pBtn1); 28 } 29 30 if (escapeButton == 0) msg.setEscapeButton(pBtn0); 31 if (!button1.isEmpty()) 32 { 33 if (escapeButton == 1) msg.setEscapeButton(pBtn1); 34 } 35 36 if (topLeft.x() >= 0 && topLeft.y() >= 0) msg.move(topLeft); 37 38 return msg.exec(); //返回用戶點擊的 按鈕的 id 39 }
?
? ?
轉載于:https://www.cnblogs.com/lt47/p/5885242.html
總結
以上是生活随笔為你收集整理的Qt msgBox 快捷版的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 男方精子成活率(40%)能在湘雅医院做三
- 下一篇: 盼友再世重逢下一句是什么呢?