update QTableWidget on item change
-
i have a class CustomDelegate (derived from QDialog). there i store a data member of type QTableWidget, and i've set a custom delegate (derived from QItemDelegate) on the table widget. i've also overridden createEditor(), setModelData(), setEditorData(), updateEditorGeometry() and eventFilter() methods.
in createEditor() i create an object of a class CustomButton (derived from QPushButton) and on that button i installEventFilter() the delegate and return it, just as usual:
QWidget *CustomDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex &index) const { CustomButton *button = new CustomButton(parent); const button->installEventFilter(const_cast<CustomDelegate*>(this)); return button; }
the code is supposed to open the editor (which contains some items) on button double click, and when the user chooses one of the items, the button is updated with text related to the item. simple. initially i have some rows with default text.
setModelData() and setEditorData() do it, but they don't work as expected.
when i choose an item, its info IS updated on the button. BUT i HAVE to go to another cell so that setModelData() and setEditorData() will be called and the table widget will be updated with the new info.
if i don't go to another cell and hit ok button, my changes won't be saved, but if i go to another cell, i'll see the new info ON the cell and ok will remember my changes.
what am i doing wrong?
-
Hi,
Take a look at the Star delegate example. It shows what you want to achieve.