PDA

View Full Version : centering qmessagebox in mainwindow parent



mcarter
5th October 2011, 19:56
Let me explain a bit of the issue since it does not seem to be the normal dialog/parent centering issue.

The basic premise is that with a push of a button I create a new MainWindow to display some info from a file, passing in the filename to the constructor. Instead of having to do a series of checks before creating the MainWindow, I let the main window do some checking . . . empty string, file exists, and processing errors. When the MainWindow is shown and there are no errors, then the normal MainWindow will appear with the various widgets. If there are errors, I would like the MainWindow to appear but with a child MessageBox dialog centered and on top of the MainWindow. Then when the dialog is closed, the MainWindow would be closed as well.

I was able to get most of the pieces working except centering the QMessageBox over the MainWindow. Since I create the MessageBox in the constructor of the MainWindow and show this dialog before the MainWindow is actually shown, the dialog does not center itself like normal dialogs would. I have also tried to capture the showEvent and resizeEvent of the parent to move the dialog appropriately but to no avail . . . parent geometry top left is always (0,0).

I could make the same call and then have an isValid() check function before I do the show and if there are errors then retrieve the message and popup the error messagebox, but I was wondering if there was a way to get the messagebox centered with the described setup.

mcarter
10th October 2011, 18:23
I resolved the issue by internally making sure to do a show on the MainWindow in the constructor before doing a show on the MessageBox dialog.