Results 1 to 6 of 6

Thread: QtDesigner Layout Help

  1. #1
    Join Date
    Jun 2006
    Posts
    12
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QtDesigner Layout Help

    Hello-

    I've been trying to use QtDesigner 4.x to layout my GUI, but I haven't had much luck understanding how one is supposed to use the Designer's layout managers. Try as I might, after manipulating the sizePolicies for each of the Widgets in my mainwindow, the layout manager always screws up my ratios. For instance, if I have three widgets:

    (1) A tree view along the left hand side of the main window (from top to bottom). I want this tree view to take up 100% of the vertical height and 25% of the horizontal height.

    (2) Next to the tree view (1), I have added a frame that will soon encapsulate a widget of my own design. I would like this to have a width of the remaining 75% of the main window and a height of 75% of the main window.

    (3) Under the frame (2), I have added a table view. This width should also be 75% of the main window and a height of the remaining 25% of the main window.

    In order to try to get this to work, as far as I understand, I need to set all of the size policies (both H and V) of all of the widgets to preferred and then manipulate Hstretch and Vstretch to set up the ratios to equate to the precentages above (why Qt doesn't just support percentages, I have no idea, but that's probably another discussion). Once I have the ratios set, I hit the background of the window and then hit Grid layout. Well, that didn't work. So after going changing these stretch values sometimes systematically and sometimes randomly for several hours, I have found that (a) I don't understand how to use designer to set up widgets in relative sizes, and (b) I can't seem to problem solve my way through it. So, could someone please point me in the direction of a website or discussion on this subject? I can't imagine that I am the only one that is having trouble with this. thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QtDesigner Layout Help

    Something like this (see the attachment)?

    All I did is:
    • placed the widgets,
    • selected the main window and then "Lay Out in a Grid",
    • set tree view's horizontalStretch to 1,
    • set frame's horizontal and vertical stretch to 3,
    • and finally set table view's vertical stretch to 1.


    Do you use the newest Qt version?
    Attached Files Attached Files

  3. The following 2 users say thank you to jacek for this useful post:

    gfunk (6th July 2006), mentat (6th July 2006)

  4. #3
    Join Date
    Jun 2006
    Posts
    12
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QtDesigner Layout Help

    Quote Originally Posted by jacek
    Something like this (see the attachment)?

    All I did is:
    • placed the widgets,
    • selected the main window and then "Lay Out in a Grid",
    • set tree view's horizontalStretch to 1,
    • set frame's horizontal and vertical stretch to 3,
    • and finally set table view's vertical stretch to 1.


    Do you use the newest Qt version?
    I am using 4.1.3 on OS X.

    But then when I add splitters to the mix (between each of the widgets) in order to allow dynamic resizing, the real problems begin to manifest themselves. Sorry, I left this key bit of info out of the original posting since I only found that the problem was splitter-dependent after I had posted my question. Anyway, in this case, I have left your Hratios in place between the frame and the table, added a splitter between the frame and the table and then added a splitter between the grouping of these two widgets and the tree widget. I gave the table/frame splitter an Hstretch of 3 (w/no Vstretch). This captures the Hratio between the tree and these two widgets (ie: your aforementioned 1:3 ratio). However, the Vratio between the table and the frame (ie: your 1:3 ratio) falls apart and I'm not sure why. Am I missing a key setting somewhere? Please see the attachment.
    Attached Files Attached Files

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QtDesigner Layout Help

    Indeed, splitters behave oddly (even in Qt 4.2 TP1). AFAIR you can fix that with QSplitter::setStretchFactor(), but you have to do this in code.

    QSplitter docs say:
    The initial distribution of size between the widgets is determined by the initial size of each widget.
    Which might mean that stretch factors are just ignored. Maybe the Trolls will be able to explain this behavior.

  6. #5
    Join Date
    Jun 2006
    Posts
    12
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QtDesigner Layout Help

    Quote Originally Posted by jacek
    Indeed, splitters behave oddly (even in Qt 4.2 TP1). AFAIR you can fix that with QSplitter::setStretchFactor(), but you have to do this in code.

    Which might mean that stretch factors are just ignored. Maybe the Trolls will be able to explain this behavior.
    Weird. It seems to work better when the splitter is a vertical, but when it is horizontal, all bets are off. I then thought it was the "frame" widget itself, but any other widget seems to do the same thing. I'm really at a loss at this point as I wonder how useful QtDesigner will be to my project going forward. In complex main widow-type widgets the relative size of enclosed widgets is really important, but it seems that if I want my users to be able to resize each individual widget at runtime, then I'll need to do a lot of hand coding which kinda defeats the purpose of QtDesigner.

    I'm posting a bugreport now so at the very least, we will hopefully get some understanding whether it really is a bug or some sort of "feature".

  7. #6
    Join Date
    Jun 2006
    Posts
    12
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QtDesigner Layout Help

    Hello All-

    I received a follow up from Trolltech concerning the bug report I submitted. Sure enough, the order of widget instantiation does matter. To make this work with QSplitters, you must set the stretch factors on the horizontal QSplitter (the one between the table and the frame) _before_ instantiating the vertical QSplitter between the table/frame-layout and the tree view. This works and addresses my problem perfectly. I can now have the widgets of the correct size with QSplitters between.

    The open issue is still that this order matters and that once you have set the stretch factors, with QSplitters involved, any future manipulation of stretch factors in future QtDesigner sessions will not be taken into account. The only way to manipulate stretch factors again would be to destroy the QSplitters and break the overall Grid layout, then make your changes, then re-instantiate the QSplitters in the correct order (and with correctly timed stretch factor changes to those QSplitters). Future versions of Qt may fix this problem, but it is a current problem nonetheless.

    -Lance

  8. The following user says thank you to mentat for this useful post:

    jacek (13th July 2006)

Similar Threads

  1. changing layout of a widget
    By mikro in forum Qt Programming
    Replies: 10
    Last Post: 4th August 2009, 21:21
  2. Dynamic grid layout
    By eriwik in forum Qt Programming
    Replies: 1
    Last Post: 12th June 2006, 16:19
  3. "dynamic" layout
    By hulk in forum Qt Programming
    Replies: 2
    Last Post: 9th May 2006, 08:16
  4. QT4 layout of complex dialog is very slow
    By cboles in forum Qt Programming
    Replies: 15
    Last Post: 28th April 2006, 20:57
  5. Is there a resizeable layout
    By seneca in forum Qt Tools
    Replies: 2
    Last Post: 14th January 2006, 21:04

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.