Results 1 to 2 of 2

Thread: Distribute columns in QTableView

  1. #1
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Distribute columns in QTableView

    Hi,

    Is there any quick way (already made procedure) to distribute the columns in a QTableView to cover the 100% of the view. I can see that there is resizeColumnsToContents() but if the number of columns does not exceed the size of the view a white space is left.

    Thanks,
    Carlos.

  2. #2
    Join Date
    Dec 2008
    Location
    France
    Posts
    93
    Thanked 23 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: Distribute columns in QTableView

    try this

    Qt Code:
    1. ui->tableView->horizontalHeader()->setResizeMode(3, QHeaderView::ResizeToContents);
    2.  
    3. ui->tableView->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
    4. ui->tableView->horizontalHeader()->setResizeMode(1, QHeaderView::Stretch);
    5. ui->tableView->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch);
    To copy to clipboard, switch view to plain text mode 

    Column 0,1 & 2 will stretch and assure a 100% width use of the available space, column 3 will be adjusted right.

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

    qlands (17th August 2011)

Similar Threads

  1. Validator for QTableView columns
    By sasi in forum Qt Programming
    Replies: 0
    Last Post: 6th October 2009, 08:10
  2. Don't resize columns - QTableView
    By estanisgeyer in forum Qt Programming
    Replies: 1
    Last Post: 26th January 2009, 16:59
  3. Different delegates to different Columns of QTableView.
    By kaushal_gaurav in forum Qt Programming
    Replies: 4
    Last Post: 6th August 2008, 09:17
  4. set the width of the columns of QTableView
    By zhanglr in forum Qt Programming
    Replies: 6
    Last Post: 31st July 2008, 15:29
  5. autoexpanding QTableView columns
    By ucntcme in forum Qt Programming
    Replies: 6
    Last Post: 11th March 2008, 09:28

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.