change item’s color in table-view on click
Hi
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
- {
- return colorDialog;
- }
- {
- if ( color.isValid() )
- }
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?
4 replies
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.
Hi!
Volker, I implemented this idea.
I created model’s class
- {
- Q_OBJECT
- public:
- public slots:
- };
In view’s class I call showDialogIfNeed
- {
- model->showDialogIfNeed( index );
- }
and I implemented showDialogIfNeed and overrode function flags to disable editable of color column
- {
- if ( index.column() == PrivateData::ColorOrder )
- {
- }
- }
- {
- if ( index.column() != PrivateData::ColorOrder )
- if ( index.column() == PrivateData::NameOrder )
- return flags;
- }
It works fine but function showDialogIfNeed places in Model. It is mix gui and logic.
Are there more correct solutions without the mix?
You must log in to post a reply. Not a member yet? Register here!


