Results 1 to 8 of 8

Thread: Maximumsize by layout QMainWindow

  1. #1
    Join Date
    Feb 2009
    Posts
    18
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Maximumsize by layout QMainWindow

    I'm trying to set the maximum size of a qmainwindow by means of layouts / policies. For this I tested some things in Qt Designer.

    When:
    -I create a simple dialog
    -put in there a textedit widget with a certain maximum size
    -add a layout to the dialog with layoutSizeConstraint: SetMaximumSize

    The dialog behaves as expected, I can resize, till I hit the maximum size of the child widget, then I can maximize the window no further.

    When I do the same for a QMainWindow it does not work. The centralwidget stops resizing after hitting the maximum size, but the mainwindow simply grows more border space. (This is probably due to the custom layouthandler of the qmainwindow???)

    (I know I can set maximumsize on the qmainwindow, but that is not a solution, because it would involve calculating all the extra border requirements for toolbars and the like. The size policies are used specifically to avoid that.)

    Any idea on how to tackle this? (A QT designer example or some code would be great!)

    The QT designer settings:




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

    Default Re: Maximumsize by layout QMainWindow

    Unfortunately you have to calculate the area used by toolbars and other main window thingies. It shouldn't be that hard. Just measure the size of the whole main window and substract your central widget size. What remains are all the thingies you need to consider and you can do that at any time you want. Then apply the layout constraint.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Feb 2009
    Posts
    18
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Maximumsize by layout QMainWindow

    But that is not really the idea of a managed layout?

    If I have to set maximumsize manually, I would need to reset the size each time a user decides to place the toolbar (which is free to replace) somewhere else (e.g. vertically instead of horizontally).

    The qmainwindow should honor maximumsize constraint of its centralwidget-layout, like normal dialogs do!

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

    Default Re: Maximumsize by layout QMainWindow

    A top level window honours constraint of its own layout. The ability doesn't propagate upward, it would be very bad if it did. If you set the constraint on the central widget's layout, it will honour its content's size but it won't propagate upwards to the top level window. If you want such a special feature in this particular case unfortunately you'll have to provide it yourself. A usual case is that size of contents of a widget is dependent on the parent widget, not the other way round. If you start moving toolbars or dock widgets, the central widget will adjust to the size of the whole window, regardless of the size constraint.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Feb 2009
    Posts
    18
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: Maximumsize by layout QMainWindow

    Thank you for your reply. But by top level window, you mean qmainwindow based classes?

    I think upward propagation does work in some cases, because dialogs do honor the maximumsize constraint of a layout+widget placed in them. I can see cases where it makes no sense to resize a window larger than the contents allow, and here, upward propagation saves the user from manually having to set maximumsizes on the top-level window. (and reset them each time something changes, essentially writing a kind of layout handler)

    It is the custom layout handler of the qmainwindow which does not honor upward constraints? I understand that top level windows have a more complex layout, with movable toolbars and the like, but it would be quite usefull if they let me access some of the layout policies. (like "always shrink to fit - maximumsize"...)

    (to avoid confusion:
    -downward constraints, e.g. windowsize limits the size of widgets within the window
    -upward constraints, widgets have a maximum size, which could limit the maximum size of a window containing that widget (the window does have a layout assigned to it, with setmaximumsize-policy, and in that case it will follow the sizehint of the containing widgets.)
    Last edited by captiva; 23rd February 2009 at 14:33.

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

    Default Re: Maximumsize by layout QMainWindow

    Quote Originally Posted by captiva View Post
    Thank you for your reply. But by top level window, you mean qmainwindow based classes?
    No, I mean widgets without the parent - they contain a decoration and can be moved around. The base class is irrelevant here (apart from the simple rule of a thumb that QDialog derived classes are top level unless you force them otherwise).

    I think upward propagation does work in some cases, because dialogs do honor the maximumsize constraint of a layout+widget placed in them.
    Because they are top-level widgets/windows

    It is the custom layout handler of the qmainwindow which does not honor upward constraints?
    No, it's the mechanism that doesn't propagate upwards. You place a constraint on a concrete and only one layout. If you also place a constraint on a layout of its parent widget, it will adjust.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    captiva (24th February 2009)

  8. #7
    Join Date
    Feb 2009
    Posts
    18
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Maximumsize by layout QMainWindow

    Thanks. I'm relatively new to GUI programming, so I had some concepts/terminology mixed up. I think I'm beginning to understand

    But in this case the conclusion of the story is: it is not useful to put a layout & constraint on the centralwidget because the parent/toplevel qmainwindow has its own layout that will adjust anyway.

    (I cannot assign layouts directly to the qmainwindow, so that is what I meant with "qmainwindow has a custom layout handler". I thought I could get similar behaviour as a qdialog toplevel window, by assigning a layouthandler to the centralwidget, but that is not the case. The qmainwindow toplevel handler overrules..)

    So the only solution to my problem is to call setmaximumsize, and do some kind of event-detection to set new sizes if a user decides to place a toolbar somewere else. (Do you have some example code lying around? )

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

    Default Re: Maximumsize by layout QMainWindow

    Quote Originally Posted by captiva View Post
    But in this case the conclusion of the story is: it is not useful to put a layout & constraint on the centralwidget because the parent/toplevel qmainwindow has its own layout that will adjust anyway.
    Yes, that's true. You can try applying a constraint to both layouts at once though.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. changing layout of a widget
    By mikro in forum Qt Programming
    Replies: 10
    Last Post: 4th August 2009, 20:21
  2. Qt like Layout Manager available for .NET platform
    By vkhaitan in forum Qt Programming
    Replies: 0
    Last Post: 5th November 2008, 13:36
  3. QMainWindow setCentralWidget from ui widget, Qt4
    By alan in forum Qt Programming
    Replies: 5
    Last Post: 13th May 2008, 13:00
  4. Qt layout memory issue
    By bunjee in forum Qt Programming
    Replies: 9
    Last Post: 25th August 2007, 17:11
  5. Resizing problems when applying a layout
    By JimBrown in forum Newbie
    Replies: 1
    Last Post: 21st February 2007, 22:54

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.