Results 1 to 2 of 2

Thread: QMainWindow setting normal size

  1. #1
    Join Date
    Apr 2013
    Posts
    64
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default QMainWindow setting normal size

    Question 1.

    I would like to start a main window maximized. I also want to allow the user to restore. When the user restores the window first time, I want the window to be a particular size, say 500*400. Later user may change the size with mouse. I am looking for something like resize() function which will not act immediately (currently it is Maximized view) and will act when viewNormal() is called or restore button is clicked.

    Question 2.
    Is there any way to get the size of maximized window when it is not actually maximized? The Desktop size gives the size without considering Window Task Bar and hence that height/widht is slightly larger than maximized window. I dont want to show the window maximized. But I want to do some calculations based on the hieght available for maximized window.
    Last edited by mqt; 12th July 2013 at 11:02.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QMainWindow setting normal size

    In short the answer is yes to both the questions.

    1. Implement sizeHint() function for mainwindow
    2. Use qApp->desktop()->availableGeometry();

    Here is an example.
    Qt Code:
    1. class MainWindow : public QMainWindow
    2. {
    3. public:
    4. explicit MainWindow(QWidget * parent = 0)
    5. : QMainWindow(parent)
    6. , mSize(500, 400)
    7. {
    8. QWidget * widget = new QWidget;
    9. QVBoxLayout * layout = new QVBoxLayout(widget);
    10.  
    11. QRect r =qApp->desktop()->screenGeometry();
    12. layout->addWidget(new QLabel(QString("Desktop : (%1,%2,%3,%4)").arg(r.x()).arg(r.y()).arg(r.width()).arg(r.height())));
    13.  
    14. r =qApp->desktop()->availableGeometry();
    15. layout->addWidget(new QLabel(QString("Usable : (%1,%2,%3,%4)").arg(r.x()).arg(r.y()).arg(r.width()).arg(r.height())));
    16.  
    17. setCentralWidget(widget);
    18. }
    19.  
    20. QSize sizeHint(void) const
    21. {
    22. return mSize;
    23. }
    24.  
    25. private:
    26. const QSize mSize;
    27. };
    To copy to clipboard, switch view to plain text mode 

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

    mqt (12th July 2013)

Similar Threads

  1. Qmainwindow QWidget size
    By seltra in forum Newbie
    Replies: 1
    Last Post: 3rd October 2010, 18:46
  2. QMainWindow size management
    By chrishipp in forum Qt Programming
    Replies: 0
    Last Post: 5th March 2010, 23:50
  3. QMainWindow -> centralWidget size
    By lalesculiviu in forum Qt Programming
    Replies: 2
    Last Post: 25th October 2009, 09:40
  4. Replies: 2
    Last Post: 23rd March 2009, 17:26
  5. How to set QListWidget size MAX = QMainWindow ?
    By Kenneth in forum Qt Programming
    Replies: 3
    Last Post: 16th March 2007, 10:11

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.