Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
can i set value at model without using SetModelData()
rahi444 last edited by
I'm creaing an ComboBox object In QStyledItemDelegate::createEditor().
And Reading the model data and displaying into ComboBox in QStyledItemDelegate::setEditorData();
I know if user changes any value at combobox, we will get those selected values in SetModelData() so that we can write into Model.
But now my task is to write selected value to model witout using SetModelData();
Can anyone guide me how to do this. My questions are.
- How do i get selected values without using SetModelData().
- How can set value to Model without using SetModelData(). i mean how can i know which Model & which index to use to SetData().
You can use
model->setData(index, "data", Qt::EditRole);
its hard answer .2 as it really depends on where you mean ?
rahi444 last edited by
Thanks, but how do i get "data". I should take from User's selected checkbox.
As i told you, in SetEditorData(), i'm reading model's data and displaying in ComboBox.
As per my understanding, we can get user's selected data at SetModelData() only, but i don't have this option. In that case, do we have any other workaround to get selected data from combobox ?
JonB last edited by JonB
I don't claim to understand why you want to do this. However, does the example (teh accepted solution to it) in, say, https://stackoverflow.com/questions/36778577/qstyleditemdelegate-how-to-make-checkbox-button-to-change-its-state-on-click give you what you need? It's using https://doc.qt.io/qt-5/qstyleditemdelegate.html#editorEvent to access the widget's state in an event. Seems a bit low-level to me, but maybe that's what you do....?
Otherwise, I know the editor arranges to store the widget's value via editor widget's user property, see https://doc.qt.io/qt-5/qstyleditemdelegate.html#setModelData itself. Can you leverage that without actually calling
Finally, https://doc.qt.io/qt-5/qstyleditemdelegate.html#createEditor returns the widget created for doing the editing. Can you put your own slots/call functions on that to recognise when it's edited and retrieve its value directly?
If all else fails, what about looking at the source of the
setModelData()method you do not want to use in page https://code.woboq.org/qt5/qtbase/src/widgets/itemviews/qstyleditemdelegate.cpp.html ? You can see there what it does (looks pretty simple), and decide what you want to do compared to that, since you don't want to call it yourself for whatever reason.