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. How to customize item editing with QTreeView / QStandardItemModel?
Forum Updated to NodeBB v4.3 + New Features

How to customize item editing with QTreeView / QStandardItemModel?

Scheduled Pinned Locked Moved General and Desktop
18 Posts 2 Posters 16.5k Views 2 Watching
  • 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.
  • V Offline
    V Offline
    Violet Giraffe
    wrote on last edited by
    #9

    I use a commercial program that has a list view and uses single click to open editor. It works perfectly.

    1 Reply Last reply
    0
    • V Offline
      V Offline
      Violet Giraffe
      wrote on last edited by
      #10

      As for QInputEvent::timestamp(): it is unclear what resolution it has, or how to calculate the difference between stamps in ms. Any hints?

      1 Reply Last reply
      0
      • T Offline
        T Offline
        thEClaw
        wrote on last edited by
        #11

        Take a look at the sources (I don't have them available) or just try it out by inserting a "qDebug("%lli", event->timestamp());" into e.g. the mousePressEvent and then clicking a button twice within a rough estimate of e.g. two seconds. I think it's going to be microseconds, maybe milliseconds - should be easy to figure out.

        EDIT: I didn't find any hints in the sources, so either figure it out as described or use your own timer.

        1 Reply Last reply
        0
        • V Offline
          V Offline
          Violet Giraffe
          wrote on last edited by
          #12

          Thanks for checking.

          I'm almost done with my editing questions. One last thing: I want to prevent the editor from committing changes if it was closed in any other way than with Enter button press. Right now, it seems, only Esc will cancel the commit, any other way to close the editor will result in the data being commited.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            thEClaw
            wrote on last edited by
            #13

            For the data to be commited the setModelData-function has to be called. I mentioned that before - reimplement it and filter out what you need to.

            1 Reply Last reply
            0
            • V Offline
              V Offline
              Violet Giraffe
              wrote on last edited by
              #14

              But how do I know if the editor was closed with Enter, or in another way?

              1 Reply Last reply
              0
              • T Offline
                T Offline
                thEClaw
                wrote on last edited by
                #15

                It shouldn't matter. Maybe take a look at the closeEditor()-function - but if you really want to know about specific button presses, you might have to subclass QLineEdit (or whatever comes close to what you need) and write an editor on your own.

                Also: Read a bit in the documentation. As far as I know, the setModelData-function is always (!) called when data has to be committed (so pressing Esc wouldn't trigger it). In there the data is written to the model.

                1 Reply Last reply
                0
                • V Offline
                  V Offline
                  Violet Giraffe
                  wrote on last edited by
                  #16

                  My question was: I want to prevent the editor from committing changes if it was closed in any other way than with Enter button press.

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    thEClaw
                    wrote on last edited by
                    #17

                    Ok, then. Have a detailed look at the description of the "QStyledItemDelegate":http://qt-project.org/doc/qt-5/qstyleditemdelegate.html#details and then try to make use of the "Star Delegate Example":http://qt-project.org/doc/qt-5/qtwidgets-itemviews-stardelegate-example.html . As far as I know the only way to actively choose how the editor can be closed is by creating your own editor (it sends out a signal when things have to be commited, so you decide when that signal actually is sent). It is not too difficult, especially since you probably only need basic QLineEdit-functionality.

                    There is also "QAbstractItemDelegate::editorEvent":http://qt-project.org/doc/qt-5/qabstractitemdelegate.html#editorEvent , but it supposedly only is called when the editing starts, not when it finishes. In that case it wouldn't be of much use.

                    Good luck. :)

                    1 Reply Last reply
                    0
                    • V Offline
                      V Offline
                      Violet Giraffe
                      wrote on last edited by
                      #18

                      Thanks for the explanation!

                      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