Results 1 to 19 of 19

Thread: Main Window frame height

  1. #1
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Main Window frame height

    Hi,

    Is there anyway to get the height of the frame of the window(frame where there is the close button,...)?

    Thanks,
    Òscar Llarch i Galán

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Main Window frame height

    Yes, you can:
    Qt Code:
    1. int height = window->style()->pixelMetric(QStyle::PM_TitleBarHeight);
    To copy to clipboard, switch view to plain text mode 
    but may I ask what do you intend to do with it?
    J-P Nurmi

  3. #3
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Main Window frame height

    Hi,

    My application has toolbars, menus and docks, and I want that the central widget use all the avaiable space. So I take the application height less toolbars,menus,docks and upper frame.

    Thanks,
    Òscar Llarch i Galán

  4. #4
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Main Window frame height

    Hmm.. You shouldnt have to do that. Qt will handle the sizing for you. How are you setting up your UI?

  5. #5
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Main Window frame height

    Hi,
    Hmm.. You shouldnt have to do that. Qt will handle the sizing for you. How are you setting up your UI?
    Could you tell me how? I reimplemented the method "resizeEvent" to resize the centralWidget to the maximum width and height. Note that if Docks are resized, the centralWidget will be resized too.

    My UI is a centralWidget (the main window was done with Designer) and it has a QGridLayout that manages some windows (like OpenGL windows). So, depending on the size of the main Window and the size of the Docks, toolBars, ..., the size of the internal widget have to be resized.

    Thanks,
    Òscar Llarch i Galán

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Main Window frame height

    Quote Originally Posted by ^NyAw^ View Post
    Could you tell me how? I reimplemented the method "resizeEvent" to resize the centralWidget to the maximum width and height. Note that if Docks are resized, the centralWidget will be resized too.

    My UI is a centralWidget (the main window was done with Designer) and it has a QGridLayout that manages some windows (like OpenGL windows). So, depending on the size of the main Window and the size of the Docks, toolBars, ..., the size of the internal widget have to be resized.
    Hmm? But QMainWindow does that automatically (of course, provided that all the central widget, docks etc. are properly added via suitable methods in QMainWindow API). Size policies, stretch factors and such are there if you need to adjust resizing.
    J-P Nurmi

  7. #7
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Main Window frame height

    Hi,

    Size policies, stretch factors and such are there if you need to adjust resizing.
    So, I have to adjust the Size policies to get it automatically be done. I am right? I will read abou it. I supose that my problem is that I always try to do it myself without thinking that maybe it is done yet(maybe I have to read a little more, but sometimes I really don't know where to find the information, Qt is great but it has a lot of classes and sometimes I don't know where to find what I want).

    Thanks,
    Òscar Llarch i Galán

  8. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Main Window frame height

    Quote Originally Posted by ^NyAw^ View Post
    So, I have to adjust the Size policies to get it automatically be done. I am right? I will read abou it.
    Well, it's hard to say exactly what do you need. But you rarely need to manage any geometries by hand. Perhaps you could provide a screenshot and then explain how do you want all the child windows to behave?
    J-P Nurmi

  9. #9
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Main Window frame height

    Hi,

    Well, the only that I need is that the centralWidget of the mainWindow occupies all tha avaiable space.

    I had inserted a QSrollArea instead of the centralWidget because time ago I did'n need this behavior and the scrollBars were a good solution. Now I don't want to use scrollArea, and I want to use the maximum centralWidget size avaiable.

    Thanks,
    Òscar Llarch i Galán

  10. #10
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Main Window frame height

    Did you apply a top level layout? Unselect child widgets, open up context menu over the background of the form and select a layout. See this thread for a screenshot: http://www.qtcentre.org/forum/f-qt-d...lved-9897.html
    J-P Nurmi

  11. #11
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Main Window frame height

    Hi,

    Did you apply a top level layout?
    Sorry, I didn't said that I have a QGridLayout (all the code is handwritten). And I don't do it with Designer because the number of columns and rows of windows(like OpenGL widgets) can be modified.

    Thanks for replies, but it works using
    Qt Code:
    1. int height = window->style()->pixelMetric(QStyle::PM_TitleBarHeight);
    To copy to clipboard, switch view to plain text mode 
    as you told me.

    Next time I will try to try using size policies.

    Thanks,
    Òscar Llarch i Galán

  12. #12
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Main Window frame height

    Well, if you insist doing it wrong, I suggest you at least take a look at Window Geometry documentation. There is no need to query window's title height when placing its child widgets. You just have to choose proper methods which exclude window frame.
    J-P Nurmi

  13. #13
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Main Window frame height

    Hi,

    Well, or I don't explain it well or you don't understood me.
    Do you really think that I'm doing it wrong? Wich is the good way? I'm not able to make sizePolicies work well (expanded and maximum don't expand the centreal widget to avaiable space).

    Thanks,
    Òscar Llarch i Galán

  14. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Main Window frame height

    If you set a widget using QMainWindow::setCentralWidget, the main window will handle resizing the widget to fit the window contents. If it doesn't happen, it means that the widget you set for the central widget doesn't have a layout applied. If you apply the layout, it will work out of the box. Consider the following code:

    Qt Code:
    1. int main(int argc, char **argv){
    2. QApplication app(argc, argv);
    3. QWidget *w = new QWidget;
    4. QVBoxLayout *l = new QVBoxLayout(w); // *
    5. for(int i=0;i<5;i++){
    6. QTextEdit *te = new QTextEdit(w);
    7. // te->setGeometry(0, i*40, 200, 35); // %
    8. l->addWidget(te); // *
    9. }
    10. mw.setCentralWidget(w);
    11. mw.show();
    12. return app.exec();
    13. }
    To copy to clipboard, switch view to plain text mode 

    Try it and then comment out lines that are marked with asterisks and remove the comment from the line marked with the percent sign and try again, you'll see the difference while resizing.

  15. #15
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Main Window frame height

    Quote Originally Posted by ^NyAw^ View Post
    Do you really think that I'm doing it wrong? Wich is the good way?
    Unfortunately, yes I do. A good way is to rely on layouts and not to manually position children upon resize event. If you ever decide for example to change language or font, manually resized children will fail miserably. Layouts will take care of not only resize event but also a lot of other situations when geometries need to be managed.

    I'm not able to make sizePolicies work well (expanded and maximum don't expand the centreal widget to avaiable space).
    It's not about size policies it the layout management doesn't work at all. Size policies and stretch factors are ways to fine tune after you get layout managers properly installed and working. Either you didn't set the central widget with QMainWindow::setCentralWidget() or the central widget itself has no layout installed.
    J-P Nurmi

  16. #16
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Main Window frame height

    Hi,

    mmm...
    I have a centralWidget that have a QGridLayout manager.

    You know that when you resize Docks, remove or insert ToolBars, ... the space that centralWidget has is changed. Ok, so I only want that the centralWidget size is the corresponding size, not to ScrollBars apear.
    Think that I have 4 OpenGL widgets and I want that have to be full visible, so them have to be resized when Docks are resized.

    Thanks,
    Òscar Llarch i Galán

  17. #17
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Main Window frame height

    It's all doable using size policies. Child widgets should have the policy set to Maximum or Preferred and it should work. Check out the code I gave you - the text edits adjust their size according to the size of the main window's central widget. You may only get scroll bars if you use a scroll area - get rid of it and the problem might go away.

  18. #18
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Main Window frame height

    Hi,

    You may only get scroll bars if you use a scroll area
    Thanks, this was the problem. I removed the ScrollArea and now the centralWidget is resized to the maximum avaiable space.

    Thanks,
    Òscar Llarch i Galán

  19. #19
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Main Window frame height

    It would probably also worked if you had called setWidgetResizable(true) on the scroll area.

  20. The following user says thank you to wysota for this useful post:

    ^NyAw^ (13th November 2007)

Similar Threads

  1. Background image for main window widget using css.
    By Enygma in forum Qt Programming
    Replies: 8
    Last Post: 23rd August 2007, 15:40
  2. Replies: 15
    Last Post: 23rd March 2007, 16:16
  3. move parent window to the front.
    By hvengel in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2007, 08:41
  4. Replies: 5
    Last Post: 4th August 2006, 23:44
  5. cannot make a main window modal
    By Dark_Tower in forum Qt Programming
    Replies: 12
    Last Post: 23rd March 2006, 10:21

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.