![]() |
Home · Examples |
[Previous: Using Containers in Qt Designer][Qt Designer Manual][Next: Qt Designer's Signals and Slots Editing Mode]
Qt Designer can be used to create user interfaces for different purposes, and provides different kinds of form templates for each of these. The main window template is used to create application windows with menu bars, toolbars, and dock widgets.
The template provides a main application window which contains a menu bar and a toolbar by default; these can be removed if they are not required.
If you remove the menu bar, a new one can be created by selecting the Create Menu Bar option from the context menu, obtained by right-clicking within the main window form.
An application can only have one menu bar, but several toolbars can be added. Once created, the properties of a menu can be accessed using the Property Editor, and each menu can be accessed for this purpose via the The Object Inspector. Existing menus can be removed by opening a context menu over the label in the menu bar, and selecting Remove Menu 'menu_name'. Menus
Menus are added to the menu bar by modifying the Type Here placeholders. One of these is always present for editing purposes, and will not be displayed in the preview or in the finished window.
![]() | ![]() | Creating a Menu Double-click the placeholder item to start the editing process. The menu text is displayed using a line edit, and can be modified. |
![]() | ![]() | Insert the required text for the new menu. Inserting an ampersand character (&) causes the letter following it to be used as a mnemonic for the menu. Press Return or Enter to accept the new text, or press Escape to reject it. You can undo the editing operation later if required. |
Menus can contain any number of entries and separators, and can be nested to the required depth. Adding new entries to menus can be achieved by navigating the menu structure in the usual way.
![]() | ![]() | Creating a Menu Entry Double-click the new action placeholder to start the editing process, or double-click new separator to insert a new separator line after the last entry in the menu. The menu entry's text is displayed using a line edit, and can be modified. |
![]() | ![]() | Insert the required text for the new entry, optionally using the ampersand character (&) to mark the letter to use as a mnemonic for the entry. Press Return or Enter to accept the new text, or press Escape to reject it. The action created for this menu entry will be accessible via the Action Editor, and any associated keyboard shortcut can be set there. |
Toolbar buttons are created by using the action system to populate each toolbar, rather than by using specific button widgets from the widget box. Since actions can be represented by menu entries and toolbar buttons, they can be moved between menus and toolbars. To share an action between a menu and a toolbar, drag its icon from the Action Editor to the toolbar rather than from the menu where its entry is located.
New actions for menus and toolbars can be created in the Action Editor.Actions
With the menu bar and the toolbars in place, it's time to populate them with actions: Qt Designer provides an action editor to simplify the creation and management of actions.
![]() | The Action Editor Enable the action editor by opening the Tools menu, and switching on the Action Editor option. The action editor allows the user to create New actions, as well as deleting (Delete) actions. It also provides a search facility (Filter) using the action's text. Since Qt 4.4, Qt Designer's action editor can be viewed in the classic Icon View as well as Detailed View (see screenshot). You can also copy and paste actions between menus, toolbars and forms. |
In addition, the dialog provides the option of selecting an Icon for the action, as well as removing the current icon.
Once the action is created, it can be used wherever actions are applicable.
![]() | ![]() | Adding an Action To add an action to a menu or a toolbar, simply press the left mouse button over the action in the action editor, and drag it to where it is required. Qt Designer provides highlighted guide lines that tell you where the action will be added. Release the mouse button to add the action when you have found the right spot. |
![]() | Adding a Dock Widget To add a dock widget, simply drag one from the Containers section of the widget box, and drop it onto the main form area. Just as with other widgets, its properties can be modified with the Property Editor. Since dock widgets can be optionally floated as independent tool windows, it is useful to give them window titles by setting their windowTitle properties. This also helps to identify them on the form. |
Copyright © 2008 Trolltech | Trademarks | Qt Jambi 4.4.2_01 |