Results 1 to 3 of 3

Thread: Understanding QSizePolicy

  1. #1
    Join Date
    Mar 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Understanding QSizePolicy

    Hello,

    The more I try to understand how QSizePolicy works, I fail. I have for example a QLabel and a QListWidget at QtDesigner. I put them into a QSplitter (horizontal) and I want the QLabel expands as much as posible and the QListWidgets don't shrinks more than 100 in its height. So I choose the vertical QSizePolicy of the QLabel to Expanding and the vertical QSizePolicy of the QListWidget to Minimum (and Maximum, and all combinations) and also fixing the Minimum size to 100. Well, the applications does what he wants and the QLabel shrinks the maximum and the QListWidgets grows as he wants. I also tried all the combinations between size policies and it still fails. Furthermore, I don't want to set the minimum size and the maximum size to the same fixed value because I want that user controls the size of the widgets. I only want that at the app starts, the QLabel uses all the possible space and the QListWidget shrinks at size 100.

    Thanks in advance.

  2. #2
    Join Date
    Nov 2009
    Posts
    61
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Understanding QSizePolicy

    I don't know how it works with a splitter but if you use one of the layouts, this details you have just mentioned can be controlled with stretches; this can be added either using a separate function or simply providing a second parameter in addWidget / addLayout. For instance, I want to divide a window into two horizontal regions. I want a bottom region to stay fixed whereas the upper one to be rescaled when the window is rescaled.
    Qt Code:
    1. vBox->addWidget(new QLabel("Label 1"), 1);
    2. vBox->addWidget(new QListWidget);
    To copy to clipboard, switch view to plain text mode 
    By default, QLabel will probably flow but in the middle but when you set QSizePolicy to Maximum it may be rescaled as well. You may also want the upper part to be stretched twice as much as the bottom one. Then you can coded this as follows
    Qt Code:
    1. vBox->addWidget(new QLabel("Label 1"),2);
    2. vBox->addWidget(new QListWidget,1);
    To copy to clipboard, switch view to plain text mode 
    I cannot test this code so I cannot be 100% sure it will work but it may help you figure out something. Also, there is a good tutorial about how to use Layouts.

  3. #3
    Join Date
    Mar 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Understanding QSizePolicy

    Yes, it seems to work halfway but cannot get the behaviour I want. I do not know what to do, I can not understand the behavior of size Policies, etc. Thanks for the help.

Similar Threads

  1. Not understanding QtScript
    By zephod in forum Newbie
    Replies: 5
    Last Post: 19th April 2012, 15:43
  2. Replies: 0
    Last Post: 17th October 2011, 20:42
  3. Understanding QNetworkConfigurationManager
    By TheIndependentAquarius in forum Qt Programming
    Replies: 5
    Last Post: 21st September 2011, 12:47
  4. QUdpSocket understanding
    By ale301168 in forum Qt Programming
    Replies: 4
    Last Post: 7th July 2011, 07:33
  5. I need help understanding QGraphicsView
    By aarelovich in forum Qt Programming
    Replies: 13
    Last Post: 22nd July 2009, 20:02

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.