Qt-interest Archive, June 2007
Disabling menu items
Message 1 in thread
Hi,
I am evaluating Qt 4, and am not really clear on how menu
enabling is normally handled.
The system I'm used to (Carbon on the Mac), associates a command
ID with each menu item. Each menu item is either enabled,
disabled, or "auto-disabled". Menu items are normally set to
auto-disable, which disables them unless someone in the focus
hierarchy can respond.
When the user opens a menu, each auto-disabled item sends an
"update status" event to the widget with the focus (which
carries with it the command ID for the menu item, and gets
updated with an "I can handle that" response).
An unhandled event is sent to the parent of that widget, up to
the window, and eventually the app. If nobody handles the event,
the menu item is disabled.
When a menu item is selected, a "process command" event is sent
to the widget with the focus (and, if that view doesn't handle
the event, up through the same hierarchy until it's caught by
the app or falls off the end).
That approach makes it trivial to make menu items enable/disable
based on the current context - put the mouse in an edit field
and Paste becomes available, switch to another window and it's disabled.
There might be a disconnect here with the Mac's global menu bar
(vs a unique menu bar per window), but how is this situation
typically handled in Qt?
E.g., if I have a window that contains an edit field and some
other widgets, how would I enable a Paste action when the edit
field has the focus and disable it when it doesn't?
One way would be for widgets to keep a pointer to all the
dynamic QActions, and update them whenever they get the focus?
That means that every widget in a window needs to know about all
the menu items they can't handle, whereas I'd prefer some way
for widgets to only have to know about the ones they can handle
(and for the app/action to drive the update process, rather than
from inside each widget).
I have found some custom approaches (http://tinyurl.com/2vvp7z),
so is that the path people normally take? Or is there a part of
QAction I've missed?
-dair
___________________________________________________
mailto:dair@xxxxxxxxxx http://www.refnum.com/
--
[ signature omitted ]