Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [SOLVED] Custom delegate "createEditor" never gets called

    General and Desktop
    2
    4
    2109
    Loading More Posts
    • 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.
    • G
      goblincoding last edited by

      Good day everyone,

      Firstly, I can edit my view without the delegate without any issues (i.e. my "flags()" and "setData()" methods seem to be implemented correctly).

      Secondly, I set the delegate on the view itself via "setItemDelegate()"

      Thirdly, I have confirmed that the delegate's "setEditorData()" and "setModelData()" methods get hit every time I attempt an edit, but the "createEditor()" method is never, ever called.

      Since I've just started playing with the Model/View/Delegate idea, I have a little "playground" project where I am testing these concepts in an attempt at understanding them. The project and all the code (there isn't much) is available "here":https://www.dropbox.com/sh/k2psfo56gm1emea/AACQubfSiZeawiIPwyOvqbWXa?dl=0

      Any help will be appreciated :)

      Thanks!

      http://www.goblincoding.com

      1 Reply Last reply Reply Quote 0
      • dheerendra
        dheerendra Qt Champions 2022 last edited by

        There is mismatch in the signature of createEditor. Please look at the warnings. It says virtual createEditor(...) is hidden by your createEditor(...). So your createEditor is different from virtual createEditor(...).

        Just try the following.

        @QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;

        QWidget *DomDelegate::createEditor(QWidget *parent,
        const QStyleOptionViewItem &option,
        const QModelIndex &index) const {

        qDebug() << "I am here-Delegate"<<endl;
        QPlainTextEdit *textEdit = new QPlainTextEdit(parent);
        //QSpinBox *box = new QSpinBox(parent);
        return textEdit;
        //return box;
        }@

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        1 Reply Last reply Reply Quote 0
        • G
          goblincoding last edited by

          Wow, what a noob error :D

          Thank you for that Dheerendra, you are indeed correct, but I am not receiving any warnings...will look into the why of it...

          http://www.goblincoding.com

          1 Reply Last reply Reply Quote 0
          • G
            goblincoding last edited by

            OK, no idea why, but it seems the standard "Desktop Qt 5.3.0 GCC 64bit" kit that comes with Qt Creator does not pick these issues up. Switched to Clang and much happiness is being had all around.

            Thanks again!

            http://www.goblincoding.com

            1 Reply Last reply Reply Quote 0
            • First post
              Last post