PDA

View Full Version : QTreeWidget Items display too wide.



chris_helloworld
26th February 2010, 12:58
Hi,
Please can someone help with a problem I'm having with the QTreeWidget. The tree has only 1 column and I've set my tree up with the following so that I get appropriate scrollbars and item labels aren't truncated.

mytree->header()->setResizeMode(0, QHeaderView::ResizeToContents);
mytree->header()->setStretchLastSection(false);

The problem I have is that items in the tree seem to be sized to fit the entire width of the column. When you select and item in the tree the blue highlight is therefore stretched beyond the actual text of the item. For example, an item is selected and the highlight covers just the text. Then you sunsequently expand an item, (which results in the column being resized wider), the highlight of the selected item changes.

I want the item text only to be highlighted, (as per apps like windows explorer), and not the full width of the tree.

Any help would be appreciated.

mrvk
26th February 2010, 13:19
In order to select just the items and not the complete row, then try to do the following.

mytree->setSelectionBehaviour(QAbstractItemView::SelectIte ms);

chris_helloworld
26th February 2010, 13:36
Brilliant thanks, just what I wanted.