Congratulations to our 2022 Qt Champions!

mouse handling change in qt5 possibly broke my code

  • I've inherited a large codebase built off of Qt4.8, which has a framework built on top of the Qt framework. Due to Qt5 changes in the mouse handling, different functions are now being called in a particular context. The specific case is the left-mouse has been pressed, and is being used to rotate a 'knob'. The user moves off of the knob component, still holding the left mouse button, and then, at the same time, presses the right mouse button. Previously the knob component contextMenuEvent was getting called, but with Qt5 that isn't the case. As I didn't write this underlying framework, it is a bit daunting to go mess with it's innards.

    otoh, if I use grabMouse/releaseMouse, I get the previous, and expected, behavior. But, I am concerned based on the warnings in the documentation for grabMouse. My quick tests using grabMouse/releaseMouse work, but obviously I don't knowhow to test for the dangers warned against.

    Any advice? Is grabMouse really that dangerous? Are there some known conditions I can test against?

    Thank in advance.

    -Chris Roberts
    Meyer Sound
    Senior Software Engineer

  • Lifetime Qt Champion


    Well, the best testing is intensive testing. Let your co-worker toy with the software to see if anything bad happens. You can also write unit tests to automate that part.

    If you don't do anything funky you should not get bitten by grabMouse.

    In any case, I'd rather take a look at that underlying framework. If you are inheriting its maintenance, then it's better to know it.

  • @SGaist said:

    If you don't do anything funky you should not get bitten by grabMouse.

    Thank you oh mighty Qt Champ! ;)

    I fully agree that rectifying the framework with the new mouse handling is the proper fix, but, as usual, I am balancing this against a schedule that lines up with shipping hardware.

    Your input allows me to speak more intelligently about our options, and help our group decide the best way to spend our time.

    Thank you.

Log in to reply