[Qt-interest] Standard keys in menus
Andreas Pakulat
apaku at gmx.de
Mon Oct 19 00:10:17 CEST 2009
On 18.10.09 10:54:15, KC Jones wrote:
> First post here, pardon me if this is a well known issue. I searched
> the archives and poured over the docs to no avail, yet I can't believe
> I'm the first person to run into this...
>
> Is there a standard way to handle standard key actions in menus?
>
> I'm building my application menu and I need to add items for various
> standard keys. My app does not implement any custom actions for these
> keys and relies happily on Qt to implement the functionality on a per
> widget basis. Let's consider the delete action (just because its
> shortcut key display is non-trivial, Cut, Copy, Paste are also
> relevant here).
>
> I see the standard key definition, QKeySequence::Delete
> I add it to my edit menu by creating a delete action with the shortcut
> set to QKeySequence::Delete and the shortcut shows correctly. Nice.
> When I hit the DEL key itself, it works as expected.
> So far so good.
>
> But if I select the menu item nothing happens since I have not defined
> that slot.
> And when focus is on some widget that does not support delete, the
> menu item is not disabled.
>
> Am I really supposed to code slots for each standard key I put in the menu?
Yes. Usually thats easy though, as the delete-code is inside a slot in
the relevant widget. That means all you need to do is connect the action
to the right slot of the right widget.
> And how am I supposed to implement correct menu enable/disable sensitivity?
Listen to focus changes or enter/leave events and enable/disable the
actions.
> Unless I'm missing something, I would suggest it would be very useful
> to provide static QAction instances for many of the statdard
> QKeySequences.
Well, the problem is how should the slot be implemented by Qt in a
generic way? And how should the action decide which widget to connect
to, for example if you have multiple text edits. This is part of your
job as app developer - to put the widgets together and connect them to
create a meaningful application.
Andreas
--
Beware of a tall black man with one blond shoe.
More information about the Qt-interest-old
mailing list