Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. how to prevent QTreeView selection changing
Forum Updated to NodeBB v4.3 + New Features

how to prevent QTreeView selection changing

Scheduled Pinned Locked Moved Solved QML and Qt Quick
9 Posts 2 Posters 1.7k Views 1 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.
  • L Offline
    L Offline
    LiaoXuewei
    wrote on last edited by
    #1

    hi, all:
    How to prevent QTreeView selection changing from one node to another node by dynamic condition?

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

      Hi,

      What would this "dynamic condition" be ?

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

      L 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        What would this "dynamic condition" be ?

        L Offline
        L Offline
        LiaoXuewei
        wrote on last edited by
        #3

        Hi, It's mean control by code. Example, show a message box to the user, user can choice cancel.

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

          One possible way would be to connect to the QItemSelectionModel::selectionChanged signal and if cancel is called, re-select the deselected items. However you will likely have to block signals while doing that to avoid having it called again while manipulating the selection in that case.

          Can you explain why you want to do that that way exactly ?

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

          L 1 Reply Last reply
          1
          • SGaistS SGaist

            One possible way would be to connect to the QItemSelectionModel::selectionChanged signal and if cancel is called, re-select the deselected items. However you will likely have to block signals while doing that to avoid having it called again while manipulating the selection in that case.

            Can you explain why you want to do that that way exactly ?

            L Offline
            L Offline
            LiaoXuewei
            wrote on last edited by
            #5

            @SGaist thks for reply.
            I've considered this approach, but I think it's not the direct way.
            Is there any other way?
            We known the window closeEvent can cancel to prevent close window, i want to known if the QTreeView have some event like it?

            It's just sometimes needed.

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

              You don't answer my question: why do you need that ? "It sometimes needed" doesn't provide any context for that.

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

              L 1 Reply Last reply
              0
              • SGaistS SGaist

                You don't answer my question: why do you need that ? "It sometimes needed" doesn't provide any context for that.

                L Offline
                L Offline
                LiaoXuewei
                wrote on last edited by
                #7

                @SGaist thks for reply.
                I've already explained that before. -->Example, show a message box to the user, user can choice cancel. ---Is this information enough to answer your questions? :)

                In the delphi treeview have the OnChanging event, In c#(.net) treeview have the BeforeSelect event, there are very useful for some time.

                Generally, it use to check some process is finish, if not, cancel changing.

                I think, this event also should exists in the qtreeview.

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

                  I would rather do it the other way around: if a process has to run, don't allow modifications. If it is a cancellable process then have a button to do so explicitly. That will make the user interface clearer.

                  For the behaviour you want, you'd have to write a custom QTreeView and reimplement the mouse related methods.

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

                  L 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    I would rather do it the other way around: if a process has to run, don't allow modifications. If it is a cancellable process then have a button to do so explicitly. That will make the user interface clearer.

                    For the behaviour you want, you'd have to write a custom QTreeView and reimplement the mouse related methods.

                    L Offline
                    L Offline
                    LiaoXuewei
                    wrote on last edited by
                    #9

                    @SGaist Ok, I see. Thank you very much!

                    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