PDA

View Full Version : stretch QTableWodgetItem



Shawn
5th September 2007, 08:43
How to set the QTableWodgetItem to stretch according to the size of QTableWidget ?

Like below.

jpn
5th September 2007, 08:44
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.

Shawn
5th September 2007, 09:23
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.

jpn
5th September 2007, 09:34
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.

Shawn
5th September 2007, 09:40
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?:confused:

Shawn
5th September 2007, 09:49
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 :p