Results 1 to 5 of 5

Thread: resize qtableview

  1. #1
    Join Date
    Jul 2012
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default resize qtableview

    hello

    I have several qdockwidget and within these a qtableview, as seen in the attached picture, my problem is I want the tables are the same size of the dock.

    I tried to do this and it does not work:

    Qt Code:
    1. table-> resize (dock-> size());
    To copy to clipboard, switch view to plain text mode 

    maybe is a silly question and should go in the section of rookies do not know, but I could not really find a solution, I hope you can help me.

    thanks

    picture.jpg

  2. #2
    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: resize qtableview

    The tables in your screen shot are the same size as the dock widgets that contain them. I think what you want is for the cells in the table to expand to the full width of the table, right? To do that you need to get the columnWidth() of each column in your table, add them, then set the width of the last column to the difference between the sum and the table width.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: resize qtableview

    You can set the last section to automatically stretch to the right using the horizontal QHeaderView, something like:
    Qt Code:
    1. view->horizontalHeader()->setStretchLastSection(true);
    To copy to clipboard, switch view to plain text mode 
    You can use the QHeaderView::setResizeMode() make other columns stretch.

  4. The following 2 users say thank you to ChrisW67 for this useful post:

    d_stranz (20th September 2012), jackajack01 (20th September 2012)

  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: resize qtableview

    Thanks, ChrisW67 - I knew that method was around somewhere and spent some time looking for it, but didn't think to check in the QHeaderView docs. That's definitely the way to do it.

  6. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: resize qtableview

    I had to hunt for it also. I think that placing it in QHeaderView is counter-intuitive. It becomes even more so when you consider that there may not even be a visible header, yet it controls the width of the table columns on resize.

Similar Threads

  1. Replies: 15
    Last Post: 11th September 2012, 07:26
  2. QTableView and column resize problem
    By winkle98 in forum Qt Programming
    Replies: 5
    Last Post: 28th February 2012, 06:51
  3. Replies: 2
    Last Post: 18th October 2010, 17:58
  4. Replies: 1
    Last Post: 1st May 2010, 23:03
  5. Don't resize columns - QTableView
    By estanisgeyer in forum Qt Programming
    Replies: 1
    Last Post: 26th January 2009, 16:59

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.