Results 1 to 2 of 2

Thread: Fixed-height layout question

  1. #1
    Join Date
    Feb 2010
    Pennsylvania, USA
    Thanked 3 Times in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Unix/X11 Windows

    Default Fixed-height layout question

    I have what I think is probably a simple problem with my layout, but I can't figure out what I'm doing wrong. I'm using designer, so the code is generated, but I can provide it if necessary.

    I have a custom widget, which is designed to scale its self gracefully, and works well when stretching (you can use the generic "Widget" widget, if you want to try to replicate my problem). Below it, I have a horizontal spacer, a label, a fixed-width spin box, and another horizontal spacer. To keep the label and spin box centered, I grouped them and the spacers into a QHBoxLayout.

    Me desired behavior is: My custom widget should expand as necessary, and the spin box layout should remain the same height. At first I grouped the widget and the spin box layout into a QVBoxLayout--oops! I realized my mistake, and grouped them into a vertical QSplitter instead.

    The QSplitter works mostly as expected, but when stretching vertically, there comes a point there the spin box layout starts to stretch vertically--the child widgets don't stretch, just the layout its self.

    As I said, I'd like the only child element doing any vertical expansion to be the custom widget. Can I somehow set the height of the spin box layout to a fixed dimension, or should I group them with something else?


  2. #2
    Join Date
    Feb 2007
    Karlsruhe, Germany
    Thanked 90 Times in 88 Posts
    Qt products
    Unix/X11 Windows

    Default Re: Fixed-height layout question

    You just need to set the Vertical Stretch (in Property-Editor QWidget.sizePolicy.Vertical Stretch) of your custom-Widget to 1, and the one of your QHBoxLayout to 0.

    Stretch: . The remaining available space is divided proportional to the stretchfactors.

    Then you should also use a QVBoxLayout, as in your case the SpinBoxCell should never get a bigger height, and thus the user shall not be able to change it by means of a splitter.



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

    TheJim01 (22nd March 2010)

Similar Threads

  1. Layout question (Twitter-client-like app)
    By piotrj in forum Newbie
    Replies: 1
    Last Post: 10th January 2010, 08:47
  2. QWidget with fixed width height ratio
    By Lodorot in forum Qt Programming
    Replies: 1
    Last Post: 26th May 2009, 08:49
  3. A question about adding to layout
    By Cruz in forum Qt Programming
    Replies: 1
    Last Post: 20th January 2009, 12:41
  4. Replies: 3
    Last Post: 4th April 2008, 19:51
  5. simple thread layout question
    By mhoover in forum Qt Programming
    Replies: 1
    Last Post: 12th August 2006, 11:02

Tags for this Thread


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.