Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

26665: Toolbar buttons do not react to long clicks #26679

Conversation

krasko78
Copy link
Contributor

Resolves: #26665

This is the same issue as #16012. The fix done there appears not to have fixed it. Handling the pressAndHold signal, even directly as implemented in the fix, suppresses the click signal.

I have found a new fix: when handling the pressAndHold signal, if we do not consume it, we should set the accepted property of the mouse event to false. In this case the click event will not be suppressed. Interestingly, for pressAndHold the accepted property is true by default which means the event has to be unaccepted if not consumed. So I am reverting the fix for #16012 and am taking care of the accepted property: in FlatButton I set accepted to false to not suppress the click signal if there are no handlers or none consumes the event. On the other hand, when pressAndHold is consumed in NoteInputBar and StyledToolBarItem, accepted will be set to true.

  • I signed the CLA
  • The title of the PR describes the problem it addresses
  • Each commit's message describes its purpose and effects, and references the issue it resolves
  • If changes are extensive, there is a sequence of easily reviewable commits
  • The code in the PR follows the coding rules
  • There are no unnecessary changes
  • The code compiles and runs on my machine, preferably after each commit individually
  • I created a unit test or vtest to verify the changes I made (if applicable)

@cbjeukendrup
Copy link
Contributor

I'm not convinced that the changes in FlatButton are necessary; most FlatButtons, where there is no connection to the pressAndHold signal, react to long clicks just fine.
For performance, it is beneficial not to connect to pressAndHold when not necessary: I once looked at the Qt source code and saw that some logic is disabled when there are no connections to that signal.

In StyledToolBarItem and NoteInputBar, you could do the following:

    mouseArea.onPressAndHold: function (event) {
        if (menuLoader.isMenuOpened || !root.hasMenu) {
            event.accepted = false;
            return
        }

        root.toggleMenuOpened()
    }

So, essentially the problem is that Connections with enabled: false is apparently not the same as not connecting to the signal at all; it is still seen as a connection. Therefore, we can just as well connect to the signal directly, without Connections. To still prevent the clicked event from being swallowed, we can indeed set accepted to false.

@krasko78
Copy link
Contributor Author

Initially I had made it like what you are suggesting but thought: "nah, they'll probably suggest reverting it to the way it used to be". 😃 What you are saying makes sense to me. Press and hold needs a timer so likely this is optimized and not wasted if there are no connections. I'll change it. Thanks!

@krasko78 krasko78 force-pushed the 26665-ToolbarButtonsDoNotReactToLongClicks branch from 9a3e528 to 988b420 Compare February 26, 2025 21:06
@krasko78
Copy link
Contributor Author

There we go!

@krasko78 krasko78 force-pushed the 26665-ToolbarButtonsDoNotReactToLongClicks branch from 988b420 to cbe96f7 Compare February 26, 2025 21:26
Copy link
Contributor

@cbjeukendrup cbjeukendrup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@zacjansheski
Copy link
Contributor

Tested on MacOS 15, Windows 11, Ubuntu 22.04.3. Approved
#26665 FIXED

@cbjeukendrup cbjeukendrup merged commit 76a8b1d into musescore:master Feb 27, 2025
11 checks passed
@krasko78 krasko78 deleted the 26665-ToolbarButtonsDoNotReactToLongClicks branch February 27, 2025 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Toolbar buttons do not react to long clicks
3 participants