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. Why the push_button always keeps the state of mouse hovering?
QtWS25 Last Chance

Why the push_button always keeps the state of mouse hovering?

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 1.4k 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.
  • LimerL Offline
    LimerL Offline
    Limer
    wrote on last edited by Limer
    #1

    I comed across the problem in my own open source project.

    The project is about algorithm visulization.

    0_1521622939100_捕获.PNG

    Just as above image shows, when I click the "Start" push-button in the bottom-right of the image, the push-button will show two different states.

    1. When I click "start" and hover the mouse over the push_button a period of time, the push-button will keep the state of mouse hovering, you can see it in the below .gif images.

    0_1521623856393_1.gif

    1. When I click "start" and let the mouse leave it immediately., the push-button will back to normal state, you can see it in the below .gif images.

    0_1521623976034_2.gif

    And I don't change the push-buton stylesheet, Not change any stylesheet!

    My project is located in https://github.com/Hapoa/Visual-Algorithms.

    Because the files are a little much, so you just need to focus on the "start()" function in the "display/d_bfs.cpp" file. When click the "start" push-button, the "start()" function will run.

    raven-worxR 1 Reply Last reply
    0
    • LimerL Limer

      I comed across the problem in my own open source project.

      The project is about algorithm visulization.

      0_1521622939100_捕获.PNG

      Just as above image shows, when I click the "Start" push-button in the bottom-right of the image, the push-button will show two different states.

      1. When I click "start" and hover the mouse over the push_button a period of time, the push-button will keep the state of mouse hovering, you can see it in the below .gif images.

      0_1521623856393_1.gif

      1. When I click "start" and let the mouse leave it immediately., the push-button will back to normal state, you can see it in the below .gif images.

      0_1521623976034_2.gif

      And I don't change the push-buton stylesheet, Not change any stylesheet!

      My project is located in https://github.com/Hapoa/Visual-Algorithms.

      Because the files are a little much, so you just need to focus on the "start()" function in the "display/d_bfs.cpp" file. When click the "start" push-button, the "start()" function will run.

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Limer said in Why the push_button always keeps the state of mouse hovering?:

      Because the files are a little much, so you just need to focus on the "start()" function in the "config/d_bfs.cpp" file.

      there is no such file and function.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      LimerL 1 Reply Last reply
      0
      • raven-worxR raven-worx

        @Limer said in Why the push_button always keeps the state of mouse hovering?:

        Because the files are a little much, so you just need to focus on the "start()" function in the "config/d_bfs.cpp" file.

        there is no such file and function.

        LimerL Offline
        LimerL Offline
        Limer
        wrote on last edited by
        #3

        @raven-worx Sorry, the path is wrong.

        It is located in "display/d_bfs.cpp"

        DiracsbracketD 1 Reply Last reply
        0
        • LimerL Limer

          @raven-worx Sorry, the path is wrong.

          It is located in "display/d_bfs.cpp"

          DiracsbracketD Offline
          DiracsbracketD Offline
          Diracsbracket
          wrote on last edited by Diracsbracket
          #4

          @Limer
          This happens because you disable the start button (and therefore the mouse leave event): by disabling the button before leaving it, you lock-in the hover state.

          void SearchBase::start()
          {
              startPushButton->setEnabled(false);
             ...
            emit startSignal();
          }
          

          You can avoid this by first changing the WA_UnderMouse attribute (as found from this post)

          startPushButton->setAttribute(Qt::WA_UnderMouse, false);
          startPushButton->setEnabled(false);
          
          LimerL 1 Reply Last reply
          0
          • DiracsbracketD Diracsbracket

            @Limer
            This happens because you disable the start button (and therefore the mouse leave event): by disabling the button before leaving it, you lock-in the hover state.

            void SearchBase::start()
            {
                startPushButton->setEnabled(false);
               ...
              emit startSignal();
            }
            

            You can avoid this by first changing the WA_UnderMouse attribute (as found from this post)

            startPushButton->setAttribute(Qt::WA_UnderMouse, false);
            startPushButton->setEnabled(false);
            
            LimerL Offline
            LimerL Offline
            Limer
            wrote on last edited by
            #5

            @Diracsbracket Thank you very much. 'setAttribute()' is a perfect solution.

            DiracsbracketD 1 Reply Last reply
            0
            • LimerL Limer

              @Diracsbracket Thank you very much. 'setAttribute()' is a perfect solution.

              DiracsbracketD Offline
              DiracsbracketD Offline
              Diracsbracket
              wrote on last edited by
              #6

              @Limer
              Hi. Don't forget to mark this question as solved!

              LimerL 1 Reply Last reply
              0
              • DiracsbracketD Diracsbracket

                @Limer
                Hi. Don't forget to mark this question as solved!

                LimerL Offline
                LimerL Offline
                Limer
                wrote on last edited by Limer
                #7

                @Diracsbracket

                If so, should I always add "setAttribute(Qt::WA_UnderMouse, false)" before "PushButton->setEnabled(false)"?

                Or we only need to add it in some special scenes?

                DiracsbracketD 1 Reply Last reply
                0
                • LimerL Limer

                  @Diracsbracket

                  If so, should I always add "setAttribute(Qt::WA_UnderMouse, false)" before "PushButton->setEnabled(false)"?

                  Or we only need to add it in some special scenes?

                  DiracsbracketD Offline
                  DiracsbracketD Offline
                  Diracsbracket
                  wrote on last edited by
                  #8

                  @Limer
                  Disabling the button or any widget for that matter means you disable the events for it, so... If you don't want the same format locking-in as you had before, then I guess you must use it with all the other buttons as well, or maybe you could disable hovering altogether.

                  LimerL 1 Reply Last reply
                  0
                  • DiracsbracketD Diracsbracket

                    @Limer
                    Disabling the button or any widget for that matter means you disable the events for it, so... If you don't want the same format locking-in as you had before, then I guess you must use it with all the other buttons as well, or maybe you could disable hovering altogether.

                    LimerL Offline
                    LimerL Offline
                    Limer
                    wrote on last edited by
                    #9

                    @Diracsbracket Ok, thank you for your warm responses.

                    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