1
votes

I'm currently looking for a way to implement touch sounds for a Qt5 Quick Controls 2 app, comparable to touch sounds that are natively available on Android. However, so far I couldn't find a way to implement them reliably. The touch sounds should only occur when, e.g. a button was pressed but not when the user taps on random parts of the screen.

My first attempt was to scan the QML Object tree and connect to all clicked() signals in C++. This worked partially, but since I'm dynamically loading QML Code using a QML Loader Component I wasn't able to keep this synchronized even when I installed a filter for ChildAdded events on all objects in the tree. I also didn't catch all (sub) components with this approach because, e.g. the internally used QQuickSpinButton does not emit clicked() signals.

Has anybody ideas for alternative solutions?

1

1 Answers

0
votes

An alternative would be to do that on the application level.

Use installEventFilter on your QGuiApplication, and then in your eventFilter, react to events of type QEvent::MouseButtonPress and QEvent::MouseButtonRelease (I don't think you need to handle QEvent::TouchBegin and friends).