Skip to content
  • 0 Votes
    9 Posts
    876 Views
    JonBJ

    @bibasmall
    I'm not understanding what is going on with your const or not. The slot CommitData() must not be const. Is it??

    Hmm, you mean you call it from CEditorDelegate::createEditor(), that is const, so its this is const, and you can't then use that for the slot object? Then I really don't know why it's OK for the connect() to actual slot but not to lambda (I suspect it's this issue, not because the new CommitData(QPushButton *btn) parameter....

    Is your CommitData() const? Doesn't look like it. If you made it const does that allow the connect()?

    UPDATE
    I think this has crossed with your latest. I believe you show there you have found a way. I prefer the second one.

    Basically you have raised a "gotcha": createEditor() is const, and that prevents you from connecting a slot to this inside it, which is something one might well want to do. It (apparently) works when &CEditorDelegate::CommitData is passed on its own as a standalone argument, but not if you try a lambda with this->CommitData(). If the C++ super-experts here see this they might comment....

  • 0 Votes
    3 Posts
    507 Views
    R

    @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.

  • 0 Votes
    4 Posts
    445 Views
    JonBJ

    @rahi444
    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 setModelData()?

    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.