Results 1 to 6 of 6

Thread: stretch QTableWodgetItem

  1. #1
    Join Date
    May 2007
    Posts
    91
    Thanks
    60
    Qt products
    Qt4
    Platforms
    Windows

    Default stretch QTableWodgetItem

    How to set the QTableWodgetItem to stretch according to the size of QTableWidget ?

    Like below.
    Attached Images Attached Images

  2. #2
    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: stretch QTableWodgetItem

    See QHeaderView::setResizeMode(). You can access the horizontal header via QTableView::horizontalHeader(). In another words, it's a property of the header of the whole view, not an individual item in the view.
    J-P Nurmi

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

    Shawn (5th September 2007)

  4. #3
    Join Date
    May 2007
    Posts
    91
    Thanks
    60
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: stretch QTableWodgetItem

    Sorry, I made a mistake

    What I want exactly is to

    1.stretch the QHeaderView according to the size of the QTreeWidget
    2.stretch the QTableWidgetItem according to its content

    Because if I set the QHeaderView's ReSizeMode to "QHeaderView::ResizeToContents" or "QHeaderView::Stretch", the width of every QTableWidgetItem is fixed to the width of the QHeaderView. And I can not find any function for resizing the QTableWidgetItem.

  5. #4
    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: stretch QTableWodgetItem

    Sorry, I'm not sure if I follow. QHeaderView is what controls column widths in both QTreeView and QTableView. No particular item in a view can be of different width than what the column is. There must be at least one stretching column if you want the header to fill all available space.
    J-P Nurmi

  6. #5
    Join Date
    May 2007
    Posts
    91
    Thanks
    60
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: stretch QTableWodgetItem

    Quote Originally Posted by jpn View Post
    Sorry, I'm not sure if I follow. QHeaderView is what controls column widths in both QTreeView and QTableView. No particular item in a view can be of different width than what the column is. There must be at least one stretching column if you want the header to fill all available space.
    I understand your meaning. But after I set the QHeaderView's resizemodel to "QHeaderView::ResizeToContents", it turns out like the pic. Seems that the QheaderView only resize to the content of itself?
    Attached Images Attached Images
    • File Type: jpg 1.jpg (12.9 KB, 7 views)

  7. #6
    Join Date
    May 2007
    Posts
    91
    Thanks
    60
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: stretch QTableWodgetItem

    I found the problem.

    The setResizeModel must be called every time after adding some items to the QTableWidget.

    Now it works fine.

    Thank you very much for your help jpn

Similar Threads

  1. QTableWidget stretch a column other than the last one
    By roleroz in forum Qt Programming
    Replies: 6
    Last Post: 4th February 2015, 06:35
  2. Layouts and allowing view to stretch with main window
    By steg90 in forum Qt Programming
    Replies: 1
    Last Post: 15th May 2007, 10:30

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.