PDA

View Full Version : How to use custom widget editor with QItemDelegate



wysman
20th May 2009, 14:28
Hello,

In my project, i need to populate a ListView with different item. Those items can have différent nature, and need a custom widget for drawing and editing.

I have build a custom widget (Widget_CarteFille_Gpio) with QDesigner (1 layout, 2 label, 2 combo-box)


Widget_CarteFille_Gpio::Widget_CarteFille_Gpio (QWidget *parent) :
QWidget (parent)
{
setupUi (this);
}

Next, i try to subclass a QItemDelegate who build my new widget for the editing.


QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
Widget_CarteFille_Gpio *editor = new Widget_CarteFille_Gpio (parent);
return editor;
}

I build the project, and exec the application !
When I double click on the item my widget is not show !

I read this exemple : http://doc.qtsoftware.com/4.5/itemviews-stardelegate.html but they draw directly on a widget, this is little different of my problem.

If someone have a code exemple about draw a custom widget for viewing/editing in a ListView. I was very interresting.

Thanks
Apologize for my English !

talk2amulya
20th May 2009, 19:06
subclass QStyledItemDelegate instead of QItemDelegate..also you should read about QItemEditorCreator, QItemEditorCreatorBase and QItemEditorFactory..this will give you more knowledge about editors and you'd be able to solve problem yourself

wysman
20th May 2009, 19:20
Thanks, i will read ;)