Results 1 to 7 of 7

Thread: How to set the QTableWidget's columns width to fit the widget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2010
    Location
    Bangalore
    Posts
    52
    Thanks
    8
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to set the QTableWidget's columns width to fit the widget

    use this
    ui->tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);

  2. #2
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How to set the QTableWidget's columns width to fit the widget

    For QTableWidget::horizontalHeader().setStretchLastSec tion(true);
    Qt Code:
    1. error: C2228: left of '.setStretchLastSection' must have class/struct/union
    2. type is 'QHeaderView *'
    3. did you intend to use '->' instead?
    To copy to clipboard, switch view to plain text mode 

    And if I try this - tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
    Qt Code:
    1. error: C2027: use of undefined type 'QHeaderView'
    2. error: C2065: 'Stretch' : undeclared identifier
    To copy to clipboard, switch view to plain text mode 

    NB: It's not even giving suggestions after horizontalHeader(). I'm using Qt 5.0.2
    Last edited by rawfool; 4th June 2013 at 06:46.

  3. #3
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How to set the QTableWidget's columns width to fit the widget

    Qt Code:
    1. QTableWidget::horizontalHeader().setStretchLastSection(true);
    To copy to clipboard, switch view to plain text mode 
    Worked. Thanks

  4. #4
    Join Date
    Aug 2014
    Location
    bangalore
    Posts
    4
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Android

    Default Re: How to set the QTableWidget's columns width to fit the widget

    Quote Originally Posted by pradeepreddyg95 View Post
    use this
    ui->tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
    Hi... you suggestion was useful

  5. #5
    Join Date
    Sep 2015
    Location
    Cairo
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to set the QTableWidget's columns width to fit the widget

    I have another problem after doing this, header then cut like the this image Capture.PNG

    the second column in the first table is [Manufacturer]
    the second column header is [Apical Diameter] and the third column is [Occlusal Diameter]

    how can i make the table fit width of both header and content and also the columns resize itself to the widget's width.

    thanks

Similar Threads

  1. Replies: 0
    Last Post: 12th November 2012, 13:12
  2. Width QTableView for QCombobox with multiple columns
    By visor_ua in forum Qt Programming
    Replies: 7
    Last Post: 21st June 2011, 10:54
  3. Replies: 1
    Last Post: 13th August 2010, 06:28
  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. Replies: 1
    Last Post: 19th September 2007, 10:32

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.