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. What is (correctly) triggering setModelData in my Delegate?
Forum Updated to NodeBB v4.3 + New Features

What is (correctly) triggering setModelData in my Delegate?

Scheduled Pinned Locked Moved Unsolved General and Desktop
delegatesetmodeldata
3 Posts 2 Posters 732 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.
  • R Offline
    R Offline
    ribs
    wrote on 28 May 2021, 03:58 last edited by
    #1

    I have a weird question where my qt app is working "correctly"... but I don't know why and I'd like to.

    I'm in the middle of writing a subclassed QTreeView with a QStyledItemDelegate and a custom editor widget to edit one aspect of my model in one of the columns of my view.

    The editor widget is super simple: it's just a widget with a layout and a QLineEdit and a QPushButton.

    I've implemented the model, as well as the delegate's setEditorData and setModelData methods.

    When I start the app and double click on a cell, the editor widget is created by the delegate and shows up as expected (and setEditorData is called and populates the QLineEdit with the right thing), and then when I enter in some new text inside the editor's QLineEdit and hit <Enter>, setModelData on the delegate gets called, which modifies the model as expected, and the delegate and custom widget disappear, all as expected.

    The thing is - I don't understand what is (automatically?) triggering setModelData in my delegate. I have connected nothing to the QLineEdit's editingFinished signal: my custom editor widget doesn't listen to the QLineEdit and doesn't explicitly emit any signals, and nothing else even knows about the QLineEdit's existence. I have not even written the word "commitData" anywhere in my code yet.

    My question is: what is going on when I finish editing my QLineEdit (a signal I have attached nothing to) that causes setModelData in my delegate to be called correctly? I'd like to block this automatic thing and only commitData when I want it to.

    Sorry, I can't paste my code here (workplace has copy/paste quarantine block) but the code is pretty straightforward I think.

    1 Reply Last reply
    0
    • V Offline
      V Offline
      VRonin
      wrote on 28 May 2021, 08:35 last edited by
      #2

      QStyledItemDelegate has an event filter, QAbstractItemDelegatePrivate::editorEventFilter. When you press enter and the editor is not a QTextEdit or a QPlainTextEdit then it will invoke QAbstractItemDelegatePrivate::_q_commitDataAndCloseEditor that will call commitData

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      R 1 Reply Last reply 30 May 2021, 22:36
      4
      • V VRonin
        28 May 2021, 08:35

        QStyledItemDelegate has an event filter, QAbstractItemDelegatePrivate::editorEventFilter. When you press enter and the editor is not a QTextEdit or a QPlainTextEdit then it will invoke QAbstractItemDelegatePrivate::_q_commitDataAndCloseEditor that will call commitData

        R Offline
        R Offline
        ribs
        wrote on 30 May 2021, 22:36 last edited by
        #3

        @VRonin Aha, that has got to be it - thank you very much! Sounds like I just need to add a new eventfilter that does nothing but eat keypress events.

        1 Reply Last reply
        0

        1/3

        28 May 2021, 03:58

        • Login

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