Hey!
I have the following problem with QT model/view framework. I want to render a widget inside a table view item.
First my thought was to use
void QAbstractItemView::setIndexWidget( const QModelIndex & index, QWidget * widget )
But the documentation for this function explicitly states:
This function should only be used to display static content within the visible area corresponding to an item of data. If you want to display custom dynamic content or implement a custom editor widget, subclass QItemDelegate instead.
So they propose to use delegates here. Well, so far so good. I know that the delegates may be used to create an editor, which may be basically any QT widget. But here is the problem - I don't want this widget to be an editor - I want to render the item with this widget always. And not just "render", I need it to have the exact behavior of the widget.
Now the widget I want to use is a custom widget, which is a container of some other widgets (few check-boxes, few buttons with some layout).
The solution I consider is like this:
- Grab the look of my custom widget to a pixmap.
- Let the delegate paint itself using this pixmap.
- When the mouse is over an item cause the view to automatically start editing (I don't
know how to do it yet, but I suppose it's possible) - Let the delegate create my widget as the editor for an item.
This solution seems to work, but it smells bad for me. Can anyone thing about more elegant solution for this problem?
Thanks.