Results 1 to 7 of 7

Thread: autoexpanding QTableView columns

  1. #1
    Join Date
    Jan 2006
    Posts
    44
    Thanks
    9
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11

    Question autoexpanding QTableView columns

    I would like my QTableView columns to expand (equally preferably) to fill the width they have available (this one is inside a QStackedWidget but that shouldn't matter I'd think - providing context.).

    I can have columns resize to contests, but that isn't the issue. I could also set the size manually but well that just sucks and doesn't expand if/when the user makes the window wider.

    A "non-full-width table" looks cheap IMO, and could confuse some of the users (remember, we don't all get to choose our users' wits level )
    --
    The Real Bill

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: autoexpanding QTableView columns

    Set the resize mode of the header to "Stretch".

  3. The following 4 users say thank you to wysota for this useful post:

    Gopala Krishna (10th March 2008), tituslup (10th September 2009), tpf80 (4th October 2009), ucntcme (9th January 2008)

  4. #3
    Join Date
    Jan 2006
    Posts
    44
    Thanks
    9
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11

    Default Re: autoexpanding QTableView columns

    Thanks. Wish that was an option in Designer.
    --
    The Real Bill

  5. #4
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: autoexpanding QTableView columns

    Quote Originally Posted by wysota View Post
    Set the resize mode of the header to "Stretch".
    Ok. Now how do i set a descent size for all the columns without those ellipses initially such that scrollbars are avoided to the best extent ?

    Calling resizeColumnsToContents() and also setting wordWrap to false doesn't help me set initial size

    Screen shot 1 : The actual result.
    Screen shot 2 : The expected result.
    Attached Images Attached Images
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: autoexpanding QTableView columns

    I don't think I understand what you mean. Would you care to explain?

  7. #6
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: autoexpanding QTableView columns

    What i mean to say is,
    Now i am getting the dialog in 1st screen shot in which the last column text isn't shown fully (ellipses are shown in the end)

    What i want to achieve is the dialog in 2nd screen shot, in which the viewport of the tableview is of proper size to fit all columns without ellipses.
    How do i do that ? Calling resizeColumnsToContents still results in the first screen shot.
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: autoexpanding QTableView columns

    You mean you want the dialog to expand itself to fit its contents? It's not an easy thing to do as the table or its header doesn't report a minimum width that would fit its contents. You have to calculate the width yourself and that's the hardest part.

    You may also use QHeaderView::setStretchLastColumn(false) and optionally change the resizeMode of columns to ReizeToContents. You'll get scrollbars though...

Similar Threads

  1. Width QTableView for QCombobox with multiple columns
    By visor_ua in forum Qt Programming
    Replies: 7
    Last Post: 21st June 2011, 10:54
  2. QTableView - Enable Clicking for some columns only
    By Gabriel in forum Qt Programming
    Replies: 1
    Last Post: 23rd June 2006, 22:42

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.