tags:

views:

466

answers:

1

Hello,

I have a treewidget in my Qt form. It shows a tree of files, showing a icon representing something about them, and their name.

I entered these using treeItem->setIcon(0, *icon), and treeItem->setText(0, text) .

The reason I entered both values to the same column (0), is because otherwise the icons would not stay next to the text, rather always stick to the left, even when the text was indented to the right (because it's a child of another item).

The problem is, now I can't tell if the user clicked on the icon or on the text itself, and I need to deal with these separately.

So, is there anyway to get more info than just the treeitem and column when an object in a treewidget is clicked, or is there any way to put them on seperate columns and still have the normal behavior icons and text should have?

Thanks.

+1  A: 

I don't think there is a straight forward way to get more info, if you are simply using the clicked() or itemClicked() signals. You probably have to create a custom class that inherits QTreeWidget, and reimplement one of the virtual mouse-event functions.

mouseMoveEvent ( QMouseEvent * )
mousePressEvent ( QMouseEvent * )
mouseReleaseEvent ( QMouseEvent * )

This is not something I would recommend, unless you really know what you are doing, and really need to do it.

However, I can't remember seeing a list widget anywhere, where clicking an icon is handled differently from clicking the text in the same column. So if you are looking for "the normal behavior icons and text should have", you probably should look for another solution.

Ropez