change item’s color in table-view on click
I have table-view and I want to change color of item with help QColorDialog after click on it.
I created subclass of QItemDelegate and overrided functions createEditor and setModelData
But it doesn’t work because of model-view system considers editor widget as simple widget not dialog. And color in
is always not valid.
What are there adequate methods to solve this problem?
On our application we have similar needs (dialog to edit an item index). We do it this way:
- in the delegate check in createEditor(), if a dialog is needed for editing. If yes, return a null pointer (that restrains the view from editing the index); if no return the base class’ implementation
- connect signal QAbstractItemView::doubleClicked() [doc.qt.nokia.com] (or some overload signal from the specialized item views) to a slot
- in that slot, check if the dialog is needed, if yes create it, show it with exec() and set the value if it returns with “OK”
This way you still have inline editing for text fields, and create a dialog for the complex editing.
Volker, I implemented this idea.
I created model’s class
In view’s class I call showDialogIfNeed
- void Trend::Settings::XPenTableWidget::on_penTableView_doubleClicked(QModelIndex index)
- model->showDialogIfNeed( index );
and I implemented showDialogIfNeed and overrode function flags to disable editable of color column
It works fine but function showDialogIfNeed places in Model. It is mix gui and logic.
Are there more correct solutions without the mix?