Results 1 to 6 of 6

Thread: Setting cell width in QHBoxLayout

  1. #1
    Join Date
    Oct 2007
    Location
    Quebec, Canada
    Posts
    40
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Setting cell width in QHBoxLayout

    Hi, is there a way to set a column width in QHBoxLayout. I've been trying to play with the size policy of elements in the cell but even setting them to fixed, the cell still grow.

    Is there a kind of stretch factor that means no stretch ?

    What I'm trying to do is a kind of watch window like in Visual Studio where you have the variable name and a field beside to edit it. And since I want these line to be dragable, I thought of using multiple QHBoxLayout inside a QVBoxLayout. But the label on the left obviously won't align.

    I would have used a QGridLayout however, it does not support insert(for drag and drop).

    Would I be better served using a tricked TreeView or TableView ?

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Setting cell width in QHBoxLayout

    I've been trying to play with the size policy of elements in the cell but even setting them to fixed, the cell still grow.
    Are you sure you are doing it correctly?
    For me it works fine.
    Attached Images Attached Images
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Oct 2007
    Location
    Quebec, Canada
    Posts
    40
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Setting cell width in QHBoxLayout

    My problem is when I resize the window, how does the layout distribute the new space ? I was also testing with labels.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Setting cell width in QHBoxLayout

    My problem is when I resize the window, how does the layout distribute the new space ?
    just as I would expect - the fixed size object stays the same, the other ones expand, see images.
    Attached Images Attached Images
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Oct 2007
    Location
    Quebec, Canada
    Posts
    40
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Setting cell width in QHBoxLayout

    Well I must have been tired. I made it work. However, would you do it with nested layout like this or you would prefer a QTableWidget for example ?

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Setting cell width in QHBoxLayout

    I would have used a QGridLayout however, it does not support insert(for drag and drop).
    If indeed the QGridLayout does not support drag and drop (I didn't check this), but the nested layouts do, and you need that feature, then use the nested layouts.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. By default TreeWidget width setting in DockWidget
    By santosh.kumar in forum Qt Programming
    Replies: 0
    Last Post: 31st May 2007, 05:55

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.