Results 1 to 2 of 2

Thread: centering qmessagebox in mainwindow parent

  1. #1
    Join Date
    Nov 2009
    Location
    San Antonio, TX
    Posts
    69
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt Jambi
    Platforms
    Unix/X11 Windows

    Default centering qmessagebox in mainwindow parent

    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.

  2. #2
    Join Date
    Nov 2009
    Location
    San Antonio, TX
    Posts
    69
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Re: centering qmessagebox in mainwindow parent

    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.

Similar Threads

  1. Centering child window in parent
    By squidge in forum Qt Programming
    Replies: 2
    Last Post: 11th August 2011, 16:22
  2. QDialog problem when setting mainwindow as parent
    By superpacko in forum Qt Programming
    Replies: 3
    Last Post: 21st July 2011, 09:35
  3. Replies: 2
    Last Post: 24th January 2010, 12:46
  4. Replies: 2
    Last Post: 19th August 2008, 09:46
  5. MainWindow disappearing when loading a QMessageBox
    By fabietto in forum Qt Programming
    Replies: 14
    Last Post: 25th June 2008, 23:41

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.