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. Emit Signal When CheckState is Changed in the Model
Qt 6.11 is out! See what's new in the release blog

Emit Signal When CheckState is Changed in the Model

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 3 Posters 3.1k 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.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by mrjj
    #2

    Hi
    Im not sure why a new signal would affect your current handling.
    If you in setData emit a new signal , could you not just do what needs to be done in that slot
    without triggering other signals ?

    You could also do

    view->blockSignals(true);
       ...what..ever
    view->blockSignals(false);
    

    in that slot to prevent triggering stuff.

    if you try this way, do note
    https://doc.qt.io/qt-5/qsignalblocker.html

    Which is safer than calling blockSignals

    D 1 Reply Last reply
    0
    • mrjjM mrjj

      Hi
      Im not sure why a new signal would affect your current handling.
      If you in setData emit a new signal , could you not just do what needs to be done in that slot
      without triggering other signals ?

      You could also do

      view->blockSignals(true);
         ...what..ever
      view->blockSignals(false);
      

      in that slot to prevent triggering stuff.

      if you try this way, do note
      https://doc.qt.io/qt-5/qsignalblocker.html

      Which is safer than calling blockSignals

      D Offline
      D Offline
      DzCode
      wrote on last edited by DzCode
      #3

      @mrjj I will emit the same signal.

      For example for clicking "space" , I am emitting a signal that emit only once for multiple checking of all chekboxes. It emits after space key pressed. I also want to emit the same signal for only clicking checkbox. So that your solution is not suitable for me

      mrjjM 1 Reply Last reply
      0
      • D DzCode

        @mrjj I will emit the same signal.

        For example for clicking "space" , I am emitting a signal that emit only once for multiple checking of all chekboxes. It emits after space key pressed. I also want to emit the same signal for only clicking checkbox. So that your solution is not suitable for me

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #4

        @DzCode
        Hi
        You can call a slot without a signal, it just a normal member function.
        So you could block others and directly call the slot.
        If that would help ?

        D 1 Reply Last reply
        0
        • mrjjM mrjj

          @DzCode
          Hi
          You can call a slot without a signal, it just a normal member function.
          So you could block others and directly call the slot.
          If that would help ?

          D Offline
          D Offline
          DzCode
          wrote on last edited by
          #5

          @mrjj the main problem is how I can detect that the checkbox is clicked by mouse or not? How can I get it

          mrjjM 1 Reply Last reply
          0
          • D DzCode

            @mrjj the main problem is how I can detect that the checkbox is clicked by mouse or not? How can I get it

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #6

            @DzCode
            I assume its not a std item model so we cant use
            https://doc.qt.io/qt-5/qstandarditemmodel.html#itemChanged
            so all we have is setData.

            mrjjM D 2 Replies Last reply
            0
            • mrjjM mrjj

              @DzCode
              I assume its not a std item model so we cant use
              https://doc.qt.io/qt-5/qstandarditemmodel.html#itemChanged
              so all we have is setData.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #7

              Hi
              My friend @Ratzz suggested to use a delegate.
              You could the overwrite setData, check if item check/unchecked.
              and emit signal there. it would then come before the model handle it.

              1 Reply Last reply
              1
              • mrjjM mrjj

                @DzCode
                I assume its not a std item model so we cant use
                https://doc.qt.io/qt-5/qstandarditemmodel.html#itemChanged
                so all we have is setData.

                D Offline
                D Offline
                DzCode
                wrote on last edited by
                #8

                @mrjj custom model implemented from QAbstractItemModel is used in the project.
                Is there any way to do it with mouseevents?

                mrjjM 1 Reply Last reply
                0
                • D DzCode

                  @mrjj custom model implemented from QAbstractItemModel is used in the project.
                  Is there any way to do it with mouseevents?

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #9

                  @DzCode
                  Well you test if you click in a cell but the "checkbox" is just drawn so it cant emit any mouse events by itself.
                  Overwrite view's mousePress . remember to call base class after
                  The read the model if its currently checked or unchecked and then assume the opposite
                  when model updates. Then it might be possible to send signal before model is actually updated.

                  D 1 Reply Last reply
                  0
                  • mrjjM mrjj

                    @DzCode
                    Well you test if you click in a cell but the "checkbox" is just drawn so it cant emit any mouse events by itself.
                    Overwrite view's mousePress . remember to call base class after
                    The read the model if its currently checked or unchecked and then assume the opposite
                    when model updates. Then it might be possible to send signal before model is actually updated.

                    D Offline
                    D Offline
                    DzCode
                    wrote on last edited by
                    #10

                    @mrjj Actually, I tried it with mousepress and mouserelease and couldnt do it. In press event I hold the previous data and in release I look at the current data. I checked for the changes but not worked

                    mrjjM 1 Reply Last reply
                    0
                    • D DzCode

                      @mrjj Actually, I tried it with mousepress and mouserelease and couldnt do it. In press event I hold the previous data and in release I look at the current data. I checked for the changes but not worked

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #11

                      @DzCode
                      Hi
                      I would assume that on mouseRelease the data would still be the same.
                      But since its a bool checked/not checked could you not emit signal anyway
                      with just the opposite of what it is ? so if unchecked send checked and reverse.
                      It will first be changed after but you can get a signal before dataChanged is called ?

                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        DzCode
                        wrote on last edited by
                        #12

                        Now, I am checking the position of mouse and controlling the table item in mouse press and mouse release. Via holding a state as a private member variable, I did it.

                        Pablo J. RoginaP 1 Reply Last reply
                        1
                        • D DzCode

                          Now, I am checking the position of mouse and controlling the table item in mouse press and mouse release. Via holding a state as a private member variable, I did it.

                          Pablo J. RoginaP Offline
                          Pablo J. RoginaP Offline
                          Pablo J. Rogina
                          wrote on last edited by
                          #13

                          @DzCode said in Emit Signal When CheckState is Changed in the Model:

                          I did it.

                          does it mean your issue is solved? if so please don't forget to mark your post as such!

                          Upvote the answer(s) that helped you solve the issue
                          Use "Topic Tools" button to mark your post as Solved
                          Add screenshots via postimage.org
                          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                          1 Reply Last reply
                          1

                          • Login

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