Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
setEditorData not being called in Custom Delegate
Code_Wrangler last edited by Code_Wrangler
I have been working on implementing a custom delegate for a tree view with a standard item model for the past few days and am a little stuck. I have one problem and one question.
The problem I am having is
setEditorDatais never being called so my editors are not being populated with the correct data. The strange part is that my other functions
updateGeometryare all being called correctly. For the life of me I can't come up with a reason as to why the program would skip this function entirely in my delegate. Any suggestions would be really helpful. The work around that I have in place is just setting the data when the editor is created, but this seems silly when there is a
QDialog w/ Custom Delegate Question:
The second part of my post has to do with a question regarding a QDialog as an editor in my delegate. I think I have everything working but I want to make sure I am going about it the right way. For certain types of data stored in my model I need to edit them using a custom dialog that I created. The dialog pops up no problems, the use can edit but here is where my question comes in. I have two buttons that either accept the result using
accept()or reject the changes using
reject(). There is also a dialog function that gets the currently entered data and returns it as a list. My
setModelDatafunction calls this dialog function and then takes the returned result and sets it to the model. Does this sound correct or is there a better way I should go about it? Does the delegate handle closing the editor even though I never call
close()on the button press or in the delegate functions?
- Why isn't
- What is the proper way to return data from a QDialog and save it to the underlying model in a delegate?
- Why isn't
Code_Wrangler last edited by
So it turns out I ended up solving my own problem. The issue I was having was in my
setEditorDatadefinition I had written:
setEditorData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index)
setEditorData(QWidget *editor, const QModelIndex &index)
because the virtual declaration of
setEditorDatawas different from my definition of inputs the method was never defined and therefore was never implemented. All in all kind of dumb mistake on my part but that was the solution.
I am still curious about my second question though, if I am approaching things the right way with the dialog editor.
Hi and welcome to devnet,
The logic is the following:
- You create your widget in createEditor
- You get the data from that widget in setModelData, it's the first parameter of the function. You just have to cast it to the right type using qobject_cast
Hope it helps