Creating advanced widget in a delegate.
Hey folks,
I'm trying to display my own widget in a QListView using a QItemDelegate.
When specifying a simple widget, the delegate seems to work pretty good.
Unfortunately when I specify a more complete one, it doesn't seem to display anything.
The view is left blank, plus no resizing of the list row.
Code:
{
layout->addWidget(editor);
layout->addWidget(editor2);
layout->addWidget(editor3);
test->resize(333, 333);
test->show();
return test;
}
Any thoughts ?
Re: Creating advanced widget in a delegate.
You shouldn't resize the widget, let the view handle the geometry. If you're trying to force item size this way, it won't work. From what I see the widget you return is hardly an editor... maybe you should use setIndexWidget() instead?
Re: Creating advanced widget in a delegate.
According to the Qt documentation
void QAbstractItemView::setIndexWidget ( const QModelIndex & index, QWidget * widget )
Sets the given widget on the item at the given index, passing the ownership of the widget to the viewport.
[...]
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.
This function was introduced in Qt 4.1.
I guess setIndexWidget might not be the best way to do that.
Re: Creating advanced widget in a delegate.
I'm currently using QListView with a custom "string model" and my own delegate.
According to Qt doc :
"The QListView class provides a list or icon view onto a model."
Instead of using "QListView" I guess I could :
1/ inherit "QAbstractItemView" and create my own 'paint' routine in a new View with no delegate.
2/ "hack" the "QListView" and create my own paint routine in my delegate.
Is there a best solution?
Re: Creating advanced widget in a delegate.
Quote:
Originally Posted by
bunjee
I guess setIndexWidget might not be the best way to do that.
Depends what you want to do :)
What exactly do you want to achieve anyway? I doubt a widget with three push buttons may be appropriate to be called an "editor".
Re: Creating advanced widget in a delegate.
Something like that :
http://www.qtcentre.org/forum/f-qt-p...list-5409.html
A sort of expanded view of an item with several buttons and stuff when clicking on it.
Thanks.
Re: Creating advanced widget in a delegate.
So why do you say setIndexWidget is not fit for it? I would myself use a custom painting delegate instead of sticking a widget there anyway, but that's me :) The thing you want to put there is certainly not an editor...
Re: Creating advanced widget in a delegate.
Quote:
Originally Posted by
wysota
So why do you say setIndexWidget is not fit for it? I would myself use a custom painting delegate instead of sticking a widget there anyway, but that's me :) The thing you want to put there is certainly not an editor...
If I wanted to do like you,
how would I implement a QPushButton in the painting delegate ?
Thanks.
Re: Creating advanced widget in a delegate.
Code:
style()->drawControl(...)
and use the editorEvent to handle a click.
Using setIndexWidget() is fine too, it'll be harder to control its looks though. I surely wouldn't use an editor widget there... There is just no benefit of doing that - you don't actually edit anything. Of course it's possible to do that and you can use it if you wish. It's just I'd chose another way :)