Results 1 to 7 of 7

Thread: making MainWindow size to possible minimum size

  1. #1
    Join Date
    Nov 2015
    Posts
    128
    Thanks
    70
    Qt products
    Qt5
    Platforms
    Windows

    Default making MainWindow size to possible minimum size

    hi
    i designed all of my widgets in the MainWindow by using QGridlayout. as you know in this way some widgets are bigger than normal size and each widget takes more space that while manually i want to make it to be small, i must pull MainWindow by mouse manually. please help me to make its size how much small that how much is possible like this: myMainWindow.size(min, min).

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,620
    Thanks
    13
    Thanked 1,592 Times in 1,520 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: making MainWindow size to possible minimum size

    What happens if you call resize(10,10) after the window is displayed?

  3. The following user says thank you to ChrisW67 for this useful post:

    Alex22 (25th December 2015)

  4. #3
    Join Date
    Nov 2015
    Posts
    128
    Thanks
    70
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: making MainWindow size to possible minimum size

    Thanks ChrisW67, How can I place it in central. now when I want to show MainWindow, it shows in a small size ( that i wanted) but it goes to a bad position and I must drop it by mouse clicking in central.
    thanks for any help

  5. #4
    Join Date
    Nov 2007
    Posts
    55
    Thanks
    1
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: making MainWindow size to possible minimum size

    use setGeometry( int xPosition, int yPosition, int width, int height ), you get all you want here, no more need of resize()

  6. The following user says thank you to alainstgt for this useful post:

    Alex22 (26th December 2015)

  7. #5
    Join Date
    Nov 2015
    Posts
    128
    Thanks
    70
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: making MainWindow size to possible minimum size

    Quote Originally Posted by alainstgt View Post
    use setGeometry( int xPosition, int yPosition, int width, int height ), you get all you want here, no more need of resize()
    thanks, what are x and y positions numbers for the central position of my monitor? i want it to be showed in central position while showing.

  8. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,620
    Thanks
    13
    Thanked 1,592 Times in 1,520 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: making MainWindow size to possible minimum size

    No, x and y are the top left corner. You will have to calculate where to position it based on the geometry of the desktop and the size of the main window.

    Widget geometry property
    QDesktopWidget::screenGeometry()

  9. The following user says thank you to ChrisW67 for this useful post:

    Alex22 (26th December 2015)

  10. #7
    Join Date
    Nov 2007
    Posts
    55
    Thanks
    1
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: making MainWindow size to possible minimum size

    The following code snippet is doing what you are looking for:
    Qt Code:
    1. // set width and height of your window
    2. int width = ...
    3. int height = ...
    4. // alternatively you can get your window size
    5. // if already set:
    6. /* adjustSize(); // necessary to get updated size
    7.   QRect frame = geometry();
    8.   int width = frame.width();
    9.   int height = frame.height(); */
    10.  
    11. // get screen geometry
    12. QRect screen = QApplication::desktop()->screenGeometry();
    13.  
    14. // we center window on screen
    15. int x = ( screen.width - width ) >> 1;
    16. int y = ( screen.height - height ) >> 1;
    17. setGeometry( x, y, width, height );
    To copy to clipboard, switch view to plain text mode 

  11. The following user says thank you to alainstgt for this useful post:

    Alex22 (27th December 2015)

Similar Threads

  1. Replies: 0
    Last Post: 9th December 2014, 17:30
  2. Replies: 4
    Last Post: 20th November 2009, 12:25
  3. Replies: 2
    Last Post: 23rd March 2009, 17:26
  4. Minimum QGroupBox size
    By klnusbaum in forum Qt Programming
    Replies: 3
    Last Post: 19th June 2008, 17:22
  5. QMenuBar minimum size
    By Angelo Moriconi in forum Qt Programming
    Replies: 1
    Last Post: 14th June 2007, 21:14

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.