PDA

View Full Version : Interactive Widget with QListview



renevolution
21st February 2015, 15:01
Dear fellow Qt-Devs,

i am working on a QListView using custom Widgets and a custom delegate. Sadly, i can't figure out how i can react on user input on those widgets.
The ListView is used for dropping files into the list. Inside the list, each file is represented by my custom widget and is supposed to offer stuff like "add notes", "add associated files" etc. As far as i could see is that i shouldn't use a QListView as it is just for viewing. But if i'd use a QListWidget i could not take advantage of Model/View Programming as it doesn't support a custom model. Is there even a way to accomplish this? Or am i just totally thinking into the wrong direction?

I've already read a ton of threads but couldn't find any solution.
Any help here is really appreciated.

Thanks,
René

Santosh Reddy
23rd February 2015, 07:09
QListView QItemDelegate are intended to be used while editing an item in the view, if you need the custom widget to be displayed all the time and provide an interface to edit the item as well, then you better implement a custom listview / listwidget.

A better solution would be allow the "add notes", "add associated files" etc. feature in edit mode only, that way you can simply use QListView, custom delegates and custom editors etc..

renevolution
23rd February 2015, 11:27
A better solution would be allow the "add notes", "add associated files" etc. feature in edit mode only, that way you can simply use QListView, custom delegates and custom editors etc..

Could you elaborate this a bit more? I am super new to Qt and sadly don't really understand what you mean here.
For my current understanding every ModelItem is represented through a delegate with a widget (wich is a custom widget containing other widgets (see image attached)) in the ListView.

Is there a way to have the whole widget as an editor and how can i create it? How do i make a widget being in "edit mode"?

Thanks,
René

10959

Santosh Reddy
23rd February 2015, 13:25
Is there a way to have the whole widget as an editor and how can i create it?
Yes, use custom editor re-implmenting QStyledItemDelegate::createEditor(), and return what erver widget you want.


How do i make a widget being in "edit mode"?
This custom widget will be visible only while editing the item. Please see setEditTriggers (http://qt-project.org/doc/qt-4.8/qabstractitemview.html#editTriggers-prop)

renevolution
23rd February 2015, 14:04
I just understood the editor stuff.
Thanks a lot man. Really really helpful.