Results 1 to 6 of 6

Thread: How to center main window on screen?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Jul 2010
    Location
    Indonesia
    Posts
    83
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo
    Thanked 17 Times in 17 Posts

    Default Re: How to center main window on screen?

    Simply move the window to center then show it. This can be done by calling QWidget::show() then QWidget::move(int, int) or QWidget::move(const QPoint&). You can access information about current desktop screen geometry from QApplication::desktop()->screenGeometry().
    The implementation should be like this.
    Qt Code:
    1. QRect screenGeometry = QApplication::desktop()->screenGeometry();
    2. int x = (screenGeometry.width()-mainWindow->width()) / 2;
    3. int y = (screenGeometry.height()-mainWindow->height()) / 2;
    4. mainWindow->move(x, y);
    5. mainWindow->show();
    To copy to clipboard, switch view to plain text mode 
    ~ We are nothing in this universe ~

  2. The following user says thank you to viulskiez for this useful post:

    LarryP (16th July 2011)

Similar Threads

  1. how to show window in the center of the screen?
    By lovelypp in forum Qt Programming
    Replies: 5
    Last Post: 18th March 2014, 21:43
  2. Center dialog on screen problems
    By lalesculiviu in forum Qt Programming
    Replies: 1
    Last Post: 1st November 2009, 13:15
  3. how to put a dialog in the center of the screen
    By biswajithit in forum Qt Programming
    Replies: 4
    Last Post: 4th September 2008, 12:24
  4. Replies: 11
    Last Post: 11th August 2008, 09:14
  5. Show dialog in screen center
    By mourad in forum Qt Programming
    Replies: 1
    Last Post: 16th June 2008, 13: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
  •  
Qt is a trademark of The Qt Company.