开发者

How to make a non-blocking, non-modal QMessageBox? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably 开发者_开发技巧answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

How do I make a non-blocking, non-modal dialog equivalent to QMessageBox::information?


What do you mean by "unblocking"? Non-modal? Or one that doesn't block the execution until the user clicks ok? In both cases you'll need to create a QMessageBox manually instead of using the convenient static methods like QMessageBox::critical() etc.

In both cases, your friends are QDialog::open() and QMessageBox::open( QObject*, const char* ):

void MyWidget::someMethod() {
   ...
   QMessageBox* msgBox = new QMessageBox( this );
   msgBox->setAttribute( Qt::WA_DeleteOnClose ); //makes sure the msgbox is deleted automatically when closed
   msgBox->setStandardButtons( QMessageBox::Ok );
   msgBox->setWindowTitle( tr("Error") );
   msgBox->setText( tr("Something happened!") );
   msgBox->setIcon...
   ...
   msgBox->setModal( false ); // if you want it non-modal
   msgBox->open( this, SLOT(msgBoxClosed(QAbstractButton*)) );

   //... do something else, without blocking
}

void MyWidget::msgBoxClosed(QAbstractButton*) {
   //react on button click (usually only needed when there > 1 buttons)
}

Of course you can wrap that in your own helper functions so you don't have to duplicate it all over your code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜