PDA

View Full Version : Buttons on item in QTreeView?



joeld42
8th October 2010, 23:44
I'm trying to to put buttons on items in a QTreeView. I don't mean using buttons as an editor when clicked, but just have the button always there on some items to perform a quick action on the item.

For example, something like the little "Eject" button that appears next to removable devices in the left-hand library tree in iTunes.

I could make a delegate for the item and draw the button myself, but then I'd have to handle all the button press and hovers and everything.

Any ideas?

Thanks!
Joel

joeld42
9th October 2010, 02:27
Ok, well I figured it out eventually.

Looks like there's at least three ways to do it, this thread (http://www.qtcentre.org/threads/26916-inserting-custom-Widget-to-listview) suggests how to do it with delegates, and would work great if you had 1000s of items.

But I'm only going to have a few hundred items at most, and so I really wanted to avoid that much complexity. It turns out there's a
QAbstractItemView->setIndexWidget() that will work, and I can just make a custom widget that has my label and my buttons.

There's also QTreeWidget->setItemWidget() but I'm using QTreeView so I'm going with that.