Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

qt

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

like image 492
greshi Gupta Avatar asked Jul 09 '10 09:07

greshi Gupta


People also ask

What is a qmessagebox modal dialog?

QMessageBox is a commonly used modal dialog to display some informational message and optionally ask the user to respond by clicking any one of the standard buttons on it. Each standard button has a predefined caption, a role and returns a predefined hexadecimal number. Sr.No.

How to create a qmessagebox dialog in PyQt5?

A dialog is created with QMessageBox (). Don’t forget to import this from PyQt5. Then use the methods setIcon (), setText (), setWindowTitle () to set the window decoration.

What is the qmessagebox class?

The QMessageBox class provides a modal dialog for informing the user or for asking the user a question and receiving an answer. More... StandardButton { Ok, Open, Save, Cancel, Close, …, ButtonMask }

How do I create a message dialog in Qt?

While you can construct these dialogs yourself, Qt also provides a built-in message dialog class called QMessageBox. This can be used to create information, warning, about or question dialogs. The example below creates a simple QMessageBox and shows it.


1 Answers

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.

like image 100
Frank Osterfeld Avatar answered Sep 21 '22 21:09

Frank Osterfeld