Clickable 'buttons' on each row custom painted with QAbstractItemDelegate
-
I'd like to draw 'clickable' icons (or buttons) on each row of a QListView I'm using my own custom "QAbstractItemDelegate" derived class to paint. Those buttons may change with the custom status of the row (i have access to the underlying data structure during painting).
What's the best way to approach this?
-
use a QStyledItemDelegate and use the style to draw the button
"QStyle::drawControl":http://doc.qt.nokia.com/latest/qstyle.html#drawControl (QStyle::CE_PushButton, ...)You then have to react to the mouse clicks (which might need a subclass of the view) and can handle the clicks there.
-
So, there's no way to instantiate "live" controls in an item row? you have to "statically draw" them and handle every single mouse event for them, drawing them differently by updating flags in the row?
My requirements are a row of 2 to 5 buttons (clickable images, really), for each row, with tooltips and a "mouse on" image that'sa slightly highlighted. I can do it myself I guess, but for instance, I don't receive a "enter"/"leave" mouse events in my itemDelegate::editorEvent. I only get clicks, and I don't even get mouse move unless i click it first.
Any advice?
-
you cpould also use real widgets by using "QAbstractItemView::setIndexWidget":http://doc.qt.nokia.com/latest/qabstractitemview.html#setIndexWidget
Or you subclass the view :-( -
Or, if the licence of your application permits, look into KDE's code base and study or copy "goya" (KWidgetItemDelegate).
Widgets in item views are always a bit of a problem, that was never solved in a satisfying way, if you ask me. In this respect, QML may be the better alternative. If platform consistency isn't your main goal, you might look into using a QDeclarativeView instead of a QListView and use QML-rendered items in your list. That will allow all the interaction, highlighting, etc. you need. However, getting to look platform conformant is harder (though there are recent "labs" projects that should take you a long way).
-
That sounds great! If I can have my own "row widget" class to
Handle the creation/destruction of sub-widgets (buttons controls etc)
Paint everything that's not sub-control (my own custom paint, just like I do now with my delegate)
Process mouse events
my problem is solved!
-
[quote author="ronM71" date="1301501984"]That sounds great! If I can have my own "row widget" class to
Handle the creation/destruction of sub-widgets (buttons controls etc)
Paint everything that's not sub-control (my own custom paint, just like I do now with my delegate)
Process mouse events
my problem is solved! [/quote]
Can you paste a code snippet for me?Thx.