Results 1 to 8 of 8

Thread: QFormLayout with QTableView that expands vertically when window resizes

  1. #1
    Join Date
    Nov 2009
    Posts
    44
    Thanks
    8
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QFormLayout with QTableView that expands vertically when window resizes

    Hello! I have a window formatted using a QFormLayout that contains a set of field/label pairs, a QTableView, and then a set of buttons in a QHBoxLayout. When the window resizes, I would like the QTableView to expand in both directions - vertically to show more rows, as well as horizontally to show hidden columns.

    I have the QTableView set to horizontalHeader()->setStretchLastSection( True ); and setSizePolicy( QSizePolicy::Expanding,QSizePolicy::Expanding ); I get the horizontal resize behavior I want, but not the vertical resize behavior.

    If I use a QHBoxLayout, a QVBoxLayout or no layout, the resizing in both directions works nicely. If I have just the QTableView in a QFormLayout, it doesn't expand vertically. Do I have to switch the window's top level layout manager to a QGridLayout and then manage the row height manually, or is there something I'm missing in QFormLayout that will do the trick? Or some other approach that's better when you have a window with a lot of different widget types?

    Thanks in advance for any help!

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QFormLayout with QTableView that expands vertically when window resizes

    Hmm.

    Have you tried setting a different field growth policy?

    Or putting a the tableview together with a vertical spacer into the form layout cell?

    Cheers,
    _

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

    LynneV (18th December 2014)

  4. #3
    Join Date
    Nov 2009
    Posts
    44
    Thanks
    8
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFormLayout with QTableView that expands vertically when window resizes

    Thanks for the response! Yes, I have fieldGrowthPolicy set to AllNonFixedFieldsGrow and I've tried ExpandingFieldsGrow. But I don't see that either affects the QTableView. I kind of assumed based on the names that those properties were specific to "fields", like QLineEdit. I will try a vertical spacer... though if it works, I'd like to understand why this layout would need one, where the other layout types don't!

  5. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QFormLayout with QTableView that expands vertically when window resizes

    How about making the top level layout a QVBoxLayout? Remove the table view from the form, then stack the form layout on top of the table view in the vbox.

    Or if that isn't appropriate, some other arrangement that removes the table view from the form layout and puts both of them under the control of some other layout manager?

  6. The following user says thank you to d_stranz for this useful post:

    LynneV (18th December 2014)

  7. #5
    Join Date
    Nov 2009
    Posts
    44
    Thanks
    8
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFormLayout with QTableView that expands vertically when window resizes

    That's my basic question. If QFormLayout just doesn't support (or support well, at any rate) a mix of widgets, then yes, I have to make some other layout manager the primary parent, and then put widgets in matching layout managers - ie. QFormLayout for items with labels and other kinds for QTableView or RadioButtons or whatever. It sounds as if that's the course I'll have to take. Thanks for your help!

  8. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QFormLayout with QTableView that expands vertically when window resizes

    Quote Originally Posted by LynneV View Post
    then put widgets in matching layout managers - ie. QFormLayout for items with labels and other kinds for QTableView or RadioButtons or whatever.
    This seems to be a bit contradictory.
    If the tableviiew is an item without an associated label, why would you put it into a form layout?

    Cheers,
    _

  9. #7
    Join Date
    Nov 2009
    Posts
    44
    Thanks
    8
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFormLayout with QTableView that expands vertically when window resizes

    I'm writing a translation script for an existing application and I don't have an indicator when creating the layouts of what kind of widgets will be populating the window. It was easier to choose QFormLayout and not care what the widgets were. But I was assuming QFormLayout had the same behaviors as the more generic layout managers. I just wanted to know if there was some setting I was missing...and you were kind enough to let me know. So, off to rework it!

  10. #8
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QFormLayout with QTableView that expands vertically when window resizes

    I'd suggest trying a grid layout instead of a form layout, and making sure that things you want to grow occupy cells at one or more edges of the grid. Be sure that the grid is the primary layout for the widget so it will resize as the widget does. It may be necessary to put a phantom row or column in the grid and stretch the table to span the extra cells. These extra cells will resize without affecting the sizes of other cells in the grid (which might contain labels / buttons, etc. that you don't want to grow along with the table). Grid layouts are very adaptable, but you sometimes must trick them into a pleasing layout.

Similar Threads

  1. Resize QGraphicsItem when window resizes
    By guidupas in forum Qt Programming
    Replies: 5
    Last Post: 24th May 2014, 17:32
  2. [QTableView] change data position if table resizes
    By Schluchti in forum Qt Programming
    Replies: 1
    Last Post: 3rd March 2014, 14:51
  3. Replies: 2
    Last Post: 5th February 2012, 17:44
  4. Replies: 4
    Last Post: 20th April 2011, 02:46
  5. QGroupBox expands to maximum in BoxLayout
    By olidem in forum Newbie
    Replies: 1
    Last Post: 25th February 2010, 21:05

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.