Results 1 to 7 of 7

Thread: QTableWidget stretch a column other than the last one

  1. #1
    Join Date
    Aug 2006
    Posts
    15
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question QTableWidget stretch a column other than the last one

    I have a QTableWidget, and want the last row to be resized just if i manually do, but the first column to be the one stretching to get the full width. To have the last column stretching you can use a QTableHeaderView, but don't know how to do it for another column

    Any ideas?

    Best Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget stretch a column other than the last one


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

    giowck (18th July 2010)

  4. #3
    Join Date
    Aug 2006
    Posts
    15
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTableWidget stretch a column other than the last one

    Tried this, didn't work

    Qt Code:
    1. colorizerTable = new QTableWidget(0, 3, colorizerWidget);
    2. colorizerTable->setSortingEnabled(false);
    3. QHeaderView *headerView = new QHeaderView(Qt::Horizontal, colorizerTable);
    4. headerView->setResizeMode(0, QHeaderView::Stretch);
    5. headerView->setResizeMode(1, QHeaderView::Interactive);
    6. colorizerTable->setHorizontalHeader(headerView);
    7. colorizerTable->hideColumn(2);
    To copy to clipboard, switch view to plain text mode 

    Do you know what i'm doing wrong?

  5. #4
    Join Date
    Aug 2006
    Posts
    15
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Thumbs up Re: QTableWidget stretch a column other than the last one

    Fixed

    Qt Code:
    1. colorizerTable = new QTableWidget(0, 3, colorizerWidget);
    2. colorizerTable->setSortingEnabled(false);
    3. QHeaderView *headerView = new QHeaderView(Qt::Horizontal, colorizerTable);
    4. colorizerTable->setHorizontalHeader(headerView);
    5. headerView->setResizeMode(0, QHeaderView::Stretch);
    6. headerView->setResizeMode(1, QHeaderView::Interactive);
    7. headerView->resizeSection(1, 40);
    8. headerView->hideSection(2);
    To copy to clipboard, switch view to plain text mode 

    Just needed to set the headerView to the table before setting the headerView parameters

  6. The following 2 users say thank you to roleroz for this useful post:

    giowck (18th July 2010), swdev (22nd May 2014)

  7. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTableWidget stretch a column other than the last one

    Does it work this way?
    Qt Code:
    1. QHeaderView *headerView = colorizerTable->horizontalHeader();
    2. headerView->setResizeMode(QHeaderView::Stretch);
    3. headerView->setResizeMode(1, QHeaderView::Interactive);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  8. The following user says thank you to jpn for this useful post:

    emrares (22nd September 2009)

  9. #6
    Join Date
    Aug 2006
    Posts
    15
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Talking Re: QTableWidget stretch a column other than the last one

    Yes, it does

    Thanks

  10. #7
    Join Date
    Dec 2010
    Location
    South Africa
    Posts
    56
    Thanks
    8
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: QTableWidget stretch a column other than the last one

    Fo qt5 use setSectionResizeMode and not setResizeMode.

    Have an awesome day.

Similar Threads

  1. QTableWidget Update - slow
    By DPinLV in forum Qt Programming
    Replies: 16
    Last Post: 18th August 2006, 21:09
  2. Replies: 6
    Last Post: 5th March 2006, 21:05
  3. QTableWidget column and row sizes
    By Arthur in forum Qt Programming
    Replies: 4
    Last Post: 27th January 2006, 11:03
  4. hidden QListView column suddenly visible
    By edb in forum Qt Programming
    Replies: 10
    Last Post: 27th January 2006, 08:00
  5. How to dispay an icon in the first column of QTreeView
    By yogeshm02 in forum Qt Programming
    Replies: 1
    Last Post: 5th January 2006, 15:51

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.