QT中的消息框种类繁多,question,information ,critical,warning ,about aboutqt 等,我所知道的已经不少了,但是这些很难满足我们对其需要
于是定制消息框应运而生,之前看过念茜写的自定义Button深受启发,于是自定义了Qt的消息框。
下面看看,说明下我是在ubuntu下开发,用的emacs所以默认tab只有2个空格,可以向我索要代码,图片是iphone中用的。哈哈
void MessageBox::slotCustom()
{
QMessageBox customMsgBox;
customMsgBox.setWindowTitle("CustomMessageBox");
QPushButton *lockButton=customMsgBox.addButton(tr("Lock"),
QMessageBox::ActionRole);
QPushButton *unlockButton=customMsgBox.addButton(tr("Unlock"),
QMessageBox::ActionRole);
QPushButton *cancelButton=customMsgBox.addButton(QMessageBox::Cancel);
customMsgBox.setIconPixmap(QPixmap("/media/program/cpp/QInputDialog/png/windows.png"));
customMsgBox.setText(tr("This is a custom message box"));
customMsgBox.exec();
if(customMsgBox.clickedButton()==lockButton)
label->setText("Custom MessageBox / Lock");
if(customMsgBox.clickedButton()==unlockButton)
label->setText("Custom MessageBox /Unlock");
if(customMsgBox.clickedButton()==cancelButton)
label->setText("Custom MessageBox /Cancel");
return ;
}
来张截图看看
再来一张全屏幕的
![](http://hi.csdn.net/attachment/201108/24/0_1314176526Lh9b.gif)