An Introduction To KActions
Richard Moore, rich@kde.org
Introduction
Demonstrate the common KAction types, their uses and their appearance when
plugged into different containers. Example creates one of each action type and
shows how they work.
The Action Classes
KAction
- A basic action
- Stores all the resources for the action - name, tooltip, icons, label...
- Supports multiple containers - menus, toolbars...
- Enable and disable all uses of the action in one place
(void) new KAction( i18n( "&Perform Action" ), "fileopen", CTRL+Key_P,
object, SLOT( performAction() ),
actionCollection(), "perform_action" );
KToggleAction
- Alternates between two states, selected and unselected like a checkbox
- Can be grouped like radio buttons
(void) new KToggleAction( i18n( "&Enable/Disable Something" ), "fileopen", Key_Space,
object, SLOT( setSomethingEnabled(bool) ),
actionCollection(), "enable_something" );
KActionMenu
- An action that provides a popup menu that contains other actions
KRecentFilesAction
- A predefined action that provides a 'Recent Files' menu
- All you need to do is to define a slot that opens the URL, everything else
is handled automatically.
(void) new KRecentFilesAction( i18n( "&Recent Files" ), "fileopen", CTRL+Key_R,
object, SLOT( openURL(const KURL &) ),
actionCollection(), "open_recent" );
KSelectAction
- An action that lets the user choose between a number of items
Creating Common Actions Using KStdAction
- A factory class for creating common actions
- Makes following the standard look and feel very easy
- This is the prefered way to create actions
- You can customise that created action if you need to tweak things