How to set the QTableWodgetItem to stretch according to the size of QTableWidget ?
Like below.
How to set the QTableWodgetItem to stretch according to the size of QTableWidget ?
Like below.
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
Shawn (5th September 2007)
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.
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
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![]()
Bookmarks