Results 1 to 3 of 3

Thread: Hot to Set my QMainWindow in center

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2008
    Posts
    42
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4

    Smile Hot to Set my QMainWindow in center

    Hi friends,

    I am new to QT. I am doing an application. I want to show my window in the monitor center.

    Could any one tell me how to do this.
    I know this in VC++. But not in QT.

    Thanks in Advance.
    V. Santhosh

  2. #2
    Join Date
    Jan 2006
    Posts
    22
    Thanks
    5
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Hot to Set my QMainWindow in center

    Hi! Here is the code I use for this purpose. Change .85 to control how much of the display you want your window to fill.

    Qt Code:
    1. int screen = 0;
    2. QWidget *w = topLevelWidget();
    3. QDesktopWidget *desktop = QApplication::desktop();
    4. if (w) {
    5. screen = desktop->screenNumber(w);
    6. } else if (desktop->isVirtualDesktop()) {
    7. screen = desktop->screenNumber(QCursor::pos());
    8. } else {
    9. screen = desktop->screenNumber(this);
    10. }
    11. QRect rect(desktop->availableGeometry(screen));
    12. resize(int(rect.width() * .85), int(rect.height() * .85));
    13. move(rect.width()/2 - frameGeometry().width()/2,
    14. rect.height()/2 - frameGeometry().height()/2);
    To copy to clipboard, switch view to plain text mode 
    ImageRocket - My Qt4-based image editing program
    Project Page / Screenshots / Source

  3. #3
    Join Date
    May 2008
    Posts
    42
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4

    Talking Re: Hot to Set my QMainWindow in center

    Hi,

    Its working fine. Thanks you once again.

    Thanks and regards.
    V. Santhosh

Similar Threads

  1. set QMainWindow in the center of my desktop
    By raphaelf in forum Newbie
    Replies: 6
    Last Post: 24th July 2020, 20:29
  2. QMainWindow modal from non-qt window?
    By hickscorp in forum Qt Programming
    Replies: 3
    Last Post: 21st November 2008, 09:10
  3. QMainWindow setCentralWidget from ui widget, Qt4
    By alan in forum Qt Programming
    Replies: 5
    Last Post: 13th May 2008, 13:00
  4. QMainWindow child of a QDialog
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 16th January 2008, 07:16
  5. Replies: 18
    Last Post: 22nd February 2006, 20:51

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.