Results 1 to 3 of 3

Thread: QListWidget width always fixed to 256

  1. #1

    Default QListWidget width always fixed to 256

    Hi all

    Quickly explanation. Main window with central widget set to horizontal layout mode. Two widgets inside, one is a QListWidget and the second is a QTabWidget. Since the QListWidget will show only icons in a single "column" I want to set the width of this widget with a fixed value of 50. I'm using QT Designed to manage the window creation. In these condition it seem I can no set the width of QListWidget to a size minor than 256. The "geometry" property connected to this control into QT Designed is disabled and I can not modify it. Set horizontan "sizePolicy" as fixed and settings "minumunSize" to 50 doesn't work and the size is always 256...

    Someone have an explanation to this behaviour and can suggest me a trick for set the desired width?

    Thank you

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QListWidget width always fixed to 256

    Once you put a widget in a layout its geometry is controlled by the layout within the constraints you place on the widget, which is why geometry is greyed out.

    The layout will take the widget's sizeHint() as a starting point and work from there. QAbstractScrollArea returns QSize(256, 192) as its size hint.

    A QSizePolicy::Fixed means the layout will fix the size of the widget at the value in its sizeHint(); 256 pixels wide. You could subclass the QListWidget to return a different sizeHint() and fix your widget that way.

    If you have the QSizePolicy::Preferred (default) policy then the widget is free to be resized... you have told it the widget can be no narrower than 50 pixels, which places no constraint on the upper size, so 256 meets the constraint and that's the size you get. If you set the maximum size to 50 then the widget will be no wider than that, but may be narrower. Set both maximum and minimum to 50 and you get a fixed size.

  3. #3

    Default Re: QListWidget width always fixed to 256

    Thank you a lot, your suggestion worked. I didn't think to set both minimun and maximun size to the same value. However now I suppose I didn't understand very well how really sizePolicy work...

Similar Threads

  1. Replies: 3
    Last Post: 11th July 2012, 06:56
  2. Replies: 9
    Last Post: 13th June 2012, 15:42
  3. Fixed column width in QAbstractTableModel
    By hailflex in forum Newbie
    Replies: 1
    Last Post: 11th December 2009, 06:58
  4. QToolBox width fixed to maximum content width
    By ghorwin in forum Qt Programming
    Replies: 0
    Last Post: 10th July 2009, 09:58
  5. QWidget with fixed width height ratio
    By Lodorot in forum Qt Programming
    Replies: 1
    Last Post: 26th May 2009, 08:49

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.