Results 1 to 3 of 3

Thread: QTableWidget column width and resizing

  1. #1

    Default QTableWidget column width and resizing

    I've searched the classes documentation, but couldn't find anything about this;

    I've got my main window which can be resized, and I'm trying to work out how to get the columns in my table to maintain the width proportion while resizing, i.e. column 1 will have 20% of the total table width, column 2 50 % etc. Is there a way to do this?

    Also, I'm trying to get the last column to maintain its width no matter the size of the main window. is there way to restrict the column width to the last column, while giving the other columns the ability to stretch?

    setResizeMode appears to set resizing mode to the whole table, not individual columns.

    cheers

  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: QTableWidget column width and resizing

    There are two variants of QHeaderView::setResizeMode() - one is working on the whole header and the other on a single section.

  3. #3

    Default Re: QTableWidget column width and resizing

    Yeah, I was looking at that, but couldn't get the sections to behave the way I wanted. I can add the lines

    self.table.setColumnWidth(0,400)
    self.table.setColumnWidth(1,200)
    self.table.setColumnWidth(2,200)
    self.table.setColumnWidth(3,50)

    header.setResizeMode(3, QHeaderView.Fixed)

    and that will fix the width of the last column, but when I resize the window, the columns don't move. I tried adding these lines

    header.setResizeMode(0, QHeaderView.Stretch)
    header.setResizeMode(1, QHeaderView.Stretch)
    header.setResizeMode(2, QHeaderView.Stretch)

    but that causes erratic behavior in the column width when the window is resized, and also negates the column width that I set previously.

    It would be awesome if I could make the first 3 columns stretch, while the 4th column is fixed and is always on the tables' right side. Thats what I'm trying to achieve. Any more advice?

Similar Threads

  1. QComboBox in QTableWidget : display troubles.
    By Nyphel in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2007, 23:29
  2. Replies: 2
    Last Post: 14th August 2007, 15:16
  3. QTable column stretchable with minimum Width
    By sunil.thaha in forum Qt Programming
    Replies: 0
    Last Post: 24th April 2006, 13:17
  4. hidden QListView column suddenly visible
    By edb in forum Qt Programming
    Replies: 10
    Last Post: 27th January 2006, 08:00

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.