[Interest] Possible to know if QAction was triggered by QKeySequence or click?
bthorsen at ics.com
Wed Oct 30 12:50:46 CET 2013
Den 30-10-2013 11:12, Philipp Kursawe skrev:
> I want to detect how users usually work with the application. Do they
> click more or use the shortcuts. This way we can optimize the UI.
Thanks for the explanation. There are quite a lot of times on this
mailing list, where instead of helping someone to achieve what they
want, the proper solution is to stop them from doing it. We see that
over and over again. This is a good example of a problem that smelled
this way, but turned out to have good reasoning behind :)
Unfortunately, I think this one is really difficult to do. At first, I
was thinking it might be possible to use separate actions for toolbars,
menus etc. But you want the menus to show the shortcuts, so that doesn't
I can't help you with solving this particular problem, since I haven't
tried doing it before. But I can tell you how I would try and find the
You have to track where the global shortcuts are handled. Then hunt
through the source code to see a place where an object emits a signal or
sends an event. Those places are the spots you can hack in to and
potentially track what Qt is doing behind the scenes. You might also
sometimes find virtual methods that you can subclass and override.
A word of caution, though: If you do this, you could use parts of Qt
that isn't in the documented interface. That means you might bind your
code to single versions of Qt.
Another solution would be to create a QAction patch that emits a signal
with the origin of the trigger and submit this. You would have to use a
patched Qt yourself for a while, but at least it's a clean solution once
it gets in.
I'm sorry I couldn't give you the real solution, but I hope this helps
you to move forward.
> On Wed, Oct 30, 2013 at 11:09 AM, Bo Thorsen <bthorsen at ics.com
> <mailto:bthorsen at ics.com>> wrote:
> Den 30-10-2013 10:59, Philipp Kursawe skrev:
> > Any way to find that out?
> No. Just like you can't know if it's from the menu or toolbar or some
> other way. An action is triggered, that's the only thing that matters.
> Maybe you should try and describe what it is you want to achieve with
> all of those things. It seems like you are trying to take control in a
> way that you're not supposed to do. Frameworks always have their ways of
> doing some things, and if you deliberately try and bend them to your
> way, you are in for a frustrating ride.
> Bo Thorsen, European Engineering Manager, ICS
> Integrated Computer Solutions. Delivering World-Class Applications
> Interest mailing list
> Interest at qt-project.org <mailto:Interest at qt-project.org>
> Interest mailing list
> Interest at qt-project.org
Bo Thorsen, European Engineering Manager, ICS
Integrated Computer Solutions. Delivering World-Class Applications
More information about the Interest