Details
-
Suggestion
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
5.15.12
-
None
Description
I had a issue, which was activating a QDialog when it pops up in the current window, see:
https://forum.qt.io/topic/155599/activate-qwidget-with-a-modal-qdialog
After checking the document of QMessageBox, compare the Property-based API case:
// QMessageBox msgBox; msgBox.setText("The document has been modified."); msgBox.exec();
, and the static function case:
// 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);
It turns out to be a misunderstanding. It is the parameter parent in the constructor QDialog(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()) matters. I used it as nullptr. After passing the pointer of the main widget to QDialog, it behaviours as the same as my desire.
The issue is very interesting, even some rediculous. All guys are assuming I'm fighting with the window management mechanism of Windows OS. But it turns out to be a low-level mistake that everyone missed.
I suggest adding some words about the ```parent``` in the QDialog related documentation, and modifying the base API case of QMessagebox. The parameter parent not only affects the dialog's position and taskbar, but also has relation with the OS window management mechanism.