Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. setEditorData not being called in Custom Delegate

setEditorData not being called in Custom Delegate

Scheduled Pinned Locked Moved General and Desktop
seteditordatacustom delegateqitemdelegate
3 Posts 2 Posters 2.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Code_Wrangler
    wrote on last edited by Code_Wrangler
    #1

    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.

    setEditorData Problem:

    The problem I am having is setEditorData is never being called so my editors are not being populated with the correct data. The strange part is that my other functions createEditor, setModalData and updateGeometry are 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 setEditorData function.

    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 setModelData function 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?

    Summary

    • Why isn't setEditorData being called?
    • What is the proper way to return data from a QDialog and save it to the underlying model in a delegate?
    1 Reply Last reply
    0
    • C Offline
      C Offline
      Code_Wrangler
      wrote on last edited by
      #2

      So it turns out I ended up solving my own problem. The issue I was having was in my setEditorData definition I had written:
      setEditorData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index)
      instead of:
      setEditorData(QWidget *editor, const QModelIndex &index)
      because the virtual declaration of setEditorData was 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.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi and welcome to devnet,

        The logic is the following:

        1. You create your widget in createEditor
        2. 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

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved