Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
designer-manual.qdoc
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5 \page qtdesigner-manual.html
6
7 \title Qt Widgets Designer Manual
8 \ingroup qttools
9 \keyword Qt Widgets Designer
10
11 \QD is the Qt tool for designing and building graphical user
12 interfaces (GUIs) with \l {Qt Widgets}. For user interface design with
13 \l {Qt Quick}, see \l {Qt Design Studio Manual} {Qt Design Studio}.
14
15 You can compose and customize your windows or dialogs in a
16 what-you-see-is-what-you-get (WYSIWYG) manner, and test them using different
17 styles and resolutions. Widgets and forms created with \QD integrate
18 seamlessly with programmed code, using Qt's signals and slots mechanism, so
19 that you can easily assign behavior to graphical elements. All properties
20 set in \QD can be changed dynamically within the code. Furthermore, features
21 like widget promotion and custom plugins allow you to use your own
22 components with \QD.
23
24 \note You have the option of using \l {Qt Quick} and
25 \l {Qt Design Studio Manual}{Qt Design Studio} for user interface
26 design rather than widgets. It is a much easier way to write many kinds of
27 applications. It enables a completely customizable appearance,
28 touch-reactive elements, and smooth animated transitions, taking advantage
29 of hardware acceleration.
30
31 If you are new to \QD, you can take a look at the
32 \l{Getting To Know Qt Widgets Designer} document. For a quick tutorial on how to
33 use \QD, refer to \l{A Quick Start to Qt Widgets Designer}.
34
35 \image designer-multiple-screenshot.png {Illustration showing three screenshots
36 of the \QD editor on different operating systems}
37
38 \section1 Table of Contents
39
40 \list
41 \li \l{A Quick Start to Qt Widgets Designer}
42 \li \l{Qt Widgets Designer's Editing Modes}
43 \list
44 \li \l{Qt Widgets Designer's Widget Editing Mode}{Widget Editing Mode}
45 \li \l{Qt Widgets Designer's Signals and Slots Editing Mode}
46 {Signals and Slots Editing Mode}
47 \li \l{Qt Widgets Designer's Buddy Editing Mode}
48 {Buddy Editing Mode}
49 \li \l{Qt Widgets Designer's Tab Order Editing Mode}
50 {Tab Order Editing Mode}
51 \endlist
52 \li \l{Using Layouts in Qt Widgets Designer}
53 \li \l{Saving, Previewing and Printing Forms in Qt Widgets Designer}
54 \li \l{Using Containers in Qt Widgets Designer}
55 \li \l{Creating Main Windows in Qt Widgets Designer}
56 \li \l{Editing Resources with Qt Widgets Designer}
57 \li \l{Using Stylesheets with Qt Widgets Designer}
58 \li \l{Using a Designer UI File in Your C++ Application}
59 \li \l{Using a Designer UI File in Your Qt for Python Application}
60 \li Advanced Use
61 \list
62 \li \l{Customizing Qt Widgets Designer Forms}
63 \li \l{Using Custom Widgets with Qt Widgets Designer}
64 \li \l{Creating Custom Widgets for Qt Widgets Designer}
65 \li \l{Creating Custom Widget Extensions}
66 \li \l{Qt Widgets Designer's UI File Format}
67 \endlist
68 \endlist
69*/
70
71
72/*!
73 \page designer-to-know.html
74
75
76 \title Getting to Know Qt Widgets Designer
77
78 \image designer-screenshot.png {Screenshot showing the UI of the \QD
79 editor}
80
81 \section1 Launching Designer
82
83 Once you have installed Qt, you can start \QD in the same way as any other
84 application on the development host. You can also launch \QD directly from
85 Qt Creator. Qt Creator automatically opens all .ui files in the integrated
86 \QD, in \gui Design mode.
87
88 Generally, the integrated \QD contains the same functions as the standalone
89 \QD. For more information about the differences, see the
90 \l{http://doc.qt.io/qtcreator/index.html}{Qt Creator Manual}.
91
92 If you have large forms that do not fit in the Qt Creator \gui Design mode,
93 you can open them in the stand-alone \QD.
94
95 \section1 The User Interface
96
97 When used as a standalone application, \QD's user interface can be
98 configured to provide either a multi-window user interface (the default
99 mode), or it can be used in docked window mode. When used from within an
100 integrated development environment (IDE) only the multi-window user
101 interface is available. You can switch modes in the \gui Preferences dialog
102 from the \gui Edit menu.
103
104 In multi-window mode, you can arrange each of the tool windows to suit your
105 working style. The main window consists of a menu bar, a tool bar, and a
106 widget box that contains the widgets you can use to create your user
107 interface.
108
109 \target MainWindow
110 \table
111 \row
112 \li \inlineimage designer-main-window.png {Screenshot of the
113 \QD showing all components that can be
114 added to the window}
115 \li \b{Qt Widgets Designer's Main Window}
116
117 The menu bar provides all the standard actions for managing forms,
118 using the clipboard, and accessing application-specific help.
119 The current editing mode, the tool windows, and the forms in use can
120 also be accessed via the menu bar.
121
122 The tool bar displays common actions that are used when editing a form.
123 These are also available via the main menu.
124
125 The widget box provides common widgets and layouts that are used to
126 design components. These are grouped into categories that reflect their
127 uses or features.
128 \endtable
129
130 Most features of \QD are accessible via the menu bar, the tool bar, or the
131 widget box. Some features are also available through context menus that can
132 be opened over the form windows. On most platforms, the right mouse is used
133 to open context menus.
134
135 \target WidgetBox
136 \table
137 \row
138 \li \inlineimage designer-widget-box.png {Screenshot showing all
139 widget components for \QD}
140 \li \b{Qt Widgets Designer's Widget Box}
141
142 The widget box provides a selection of standard Qt widgets, layouts,
143 and other objects that can be used to create user interfaces on forms.
144 Each of the categories in the widget box contain widgets with similar
145 uses or related features.
146
147 You can display all of the available objects in a category by clicking
148 on the handle next to the category label. When in
149 \l{Qt Widgets Designer's Widget Editing Mode}{Widget Editing
150 Mode}, you can add objects to a form by dragging the appropriate items
151 from the widget box onto the form, and dropping them in the required
152 locations.
153
154 \QD provides a scratch pad feature that allows you to collect
155 frequently used objects in a separate category. The scratch pad
156 category can be filled with any widget currently displayed in a form
157 by dragging them from the form and dropping them onto the widget box.
158 These widgets can be used in the same way as any other widgets, but
159 they can also contain child widgets. Open a context menu over a widget
160 to change its name or remove it from the scratch pad.
161 \endtable
162
163
164 \section1 The Concept of Layouts in Qt
165
166 A layout is used to arrange and manage the elements that make up a user
167 interface. Qt provides a number of classes to automatically handle layouts
168 -- QHBoxLayout, QVBoxLayout, QGridLayout, and QFormLayout. These classes
169 solve the challenge of laying out widgets automatically, providing a user
170 interface that behaves predictably. Fortunately knowledge of the layout
171 classes is not required to arrange widgets with \QD. Instead, select one of
172 the \gui{Lay Out Horizontally}, \gui{Lay Out in a Grid}, etc., options from
173 the context menu.
174
175 Each Qt widget has a recommended size, known as \l{QWidget::}{sizeHint()}.
176 The layout manager will attempt to resize a widget to meet its size hint.
177 In some cases, there is no need to have a different size. For example, the
178 height of a QLineEdit is always a fixed value, depending on font size and
179 style. In other cases, you may require the size to change, e.g., the width
180 of a QLineEdit or the width and height of item view widgets. This is where
181 the widget size constraints -- \l{QWidget::minimumSize()}{minimumSize} and
182 \l{QWidget::maximumSize()}{maximumSize} constraints come into play. These
183 are properties you can set in the property editor. For example, to override
184 the default \l{QWidget::}{sizeHint()}, simply set
185 \l{QWidget::minimumSize()}{minimumSize} and \l{QWidget::maximumSize()}
186 {maximumSize} to the same value. Alternatively, to use the current size as
187 a size constraint value, choose one of the \gui{Size Constraint} options
188 from the widget's context menu. The layout will then ensure that those
189 constraints are met. To control the size of your widgets via code, you can
190 reimplement \l{QWidget::}{sizeHint()} in your code.
191
192 The screenshot below shows the breakdown of a basic user interface designed
193 using a grid. The coordinates on the screenshot show the position of each
194 widget within the grid.
195
196 \image addressbook-tutorial-part3-labeled-layout.png {Screenshot of an
197 address book application highlighting all widget components and
198 their position}
199
200 \note Inside the grid, the QPushButton objects are actually nested. The
201 buttons on the right are first placed in a QVBoxLayout; the buttons at the
202 bottom are first placed in a QHBoxLayout. Finally, they are put into
203 coordinates (1,2) and (2,1) of the QGridLayout.
204
205 To visualize, imagine the layout as a box that shrinks as much as possible,
206 attempting to \e squeeze your widgets in a neat arrangement, and, at the
207 same time, maximize the use of available space.
208
209 Qt's layouts help when you:
210
211 \list 1
212 \li Resize the user face to fit different window sizes.
213 \li Resize elements within the user interface to suit different
214 localizations.
215 \li Arrange elements to adhere to layout guidelines for different
216 platforms.
217 \endlist
218
219 So, you no longer have to worry about rearranging widgets for different
220 platforms, settings, and languages.
221
222 The example below shows how different localizations can affect the user
223 interface. When a localization requires more space for longer text strings
224 the Qt layout automatically scales to accommodate this, while ensuring that
225 the user interface looks presentable and still matches the platform
226 guidelines.
227
228 \table
229 \header
230 \li A Dialog in English
231 \li A Dialog in French
232 \row
233 \li \image designer-english-dialog.png {Screenshot showing an
234 address book example in English}
235 \li \image designer-french-dialog.png {Screenshot showing an
236 address book example in French}
237 \endtable
238
239 The process of laying out widgets consists of creating the layout hierarchy
240 while setting as few widget size constraints as possible.
241
242 For a more technical perspective on Qt's layout classes, refer to the
243 \l{Layout Management} documentation.
244*/
245
246
247/*!
248 \page designer-quick-start.html
249
250
251 \title A Quick Start to Qt Widgets Designer
252
253 Using \QD involves \b four basic steps:
254
255 \list 1
256 \li Choose your form and objects
257 \li Lay the objects out on the form
258 \li Connect the signals to the slots
259 \li Preview the form
260 \endlist
261
262 \image rgbController-screenshot.png {Screenshot showing an RGB controller
263 with sliders to change the red, green, and blue value}
264
265 Suppose you would like to design a small widget (see screenshot above) that
266 contains the controls needed to manipulate Red, Green and Blue (RGB) values
267 -- a type of widget that can be seen everywhere in image manipulation
268 programs.
269
270 \table
271 \row
272 \li \inlineimage designer-choosing-form.png {Screenshot showing a form of a
273 list with all components to add to the window}
274 \li \b{Choosing a Form}
275
276 You start by choosing \gui Widget from the \gui{New Form} dialog.
277 \endtable
278
279
280 \table
281 \row
282 \li \inlineimage rgbController-arrangement.png {Screenshot showing the
283 arrangement of the rgb controller components}
284 \li \b{Placing Widgets on a Form}
285
286 Drag three labels, three spin boxes and three vertical sliders on to your
287 form. To change the label's default text, simply double-click on it. You
288 can arrange them according to how you would like them to be laid out.
289 \endtable
290
291 To ensure that they are laid out exactly like this in your program, you
292 need to place these widgets into a layout. We will do this in groups of
293 three. Select the "RED" label. Then, hold down \key Ctrl while you select
294 its corresponding spin box and slider. In the \gui{Form} menu, select
295 \gui{Lay Out in a Grid}.
296
297 \table
298 \row
299 \li \inlineimage rgbController-form-gridLayout.png {Screenshot
300 showing the arrangement of the rgb controller
301 components with one component being selected}
302 \li \inlineimage rgbController-selectForLayout.png {Screenshot
303 showing the option to Lay Out in a Grid in the
304 \QD editor}
305 \endtable
306
307
308 Repeat the step for the other two labels along with their corresponding
309 spin boxes and sliders as well.
310
311 The next step is to combine all three layouts into one \b{main layout}.
312 The main layout is the top level widget's (in this case, the QWidget)
313 layout. It is important that your top level widget has a layout; otherwise,
314 the widgets on your window will not resize when your window is resized. To
315 set the layout, \gui{Right click} anywhere on your form, outside of the
316 three separate layouts, and select \gui{Lay Out Horizontally}.
317 Alternatively, you could also select \gui{Lay Out in a Grid} -- you will
318 still see the same arrangement (shown below).
319
320 \image rgbController-final-layout.png {Screenshot showing the result of the
321 final layout}
322
323 \note Main layouts cannot be seen on the form. To check if you have a main
324 layout installed, try resizing your form; your widgets should resize
325 accordingly. Alternatively, you can take a look at \QD's
326 \gui{Object Inspector}. If your top level widget does not have a layout,
327 you will see the broken layout icon next to it,
328 \inlineimage rgbController-no-toplevel-layout.png {Screenshot showing the
329 option for no toplevel layout}
330 .
331
332 When you click on the slider and drag it to a certain value, you want the
333 spin box to display the slider's position. To accomplish this behavior, you
334 need to connect the slider's \l{QAbstractSlider::}{valueChanged()} signal
335 to the spin box's \l{QSpinBox::}{setValue()} slot. You also need to make
336 the reverse connections, e.g., connect the spin box's \l{QSpinBox::}
337 {valueChanged()} signal to the slider's \l{QAbstractSlider::value()}
338 {setValue()} slot.
339
340 To do this, you have to switch to \gui{Edit Signals/Slots} mode, either by
341 pressing \key{F4} or selecting \gui{Edit Signals/Slots} from the \gui{Edit}
342 menu.
343
344 \table
345 \row
346 \li \inlineimage rgbController-signalsAndSlots.png {Screenshot of the
347 rgb controller showing the signal connection between
348 the slider and spinbox}
349 \li \b{Connecting Signals to Slots}
350
351 Click on the slider and drag the cursor towards the spin box. The
352 \gui{Configure Connection} dialog, shown below, will pop up. Select the
353 correct signal and slot and click \gui OK.
354 \endtable
355
356 \image rgbController-configure-connection1.png {Screenshot showing the
357 configuration to connect the spinbox with the slider, so the spinbox
358 value changes the slider}
359
360 Repeat the step (in reverse order), clicking on the spin box and dragging
361 the cursor towards the slider, to connect the spin box's
362 \l{QSpinBox::}{valueChanged()} signal to the slider's
363 \l{QAbstractSlider::value()}{setValue()} slot.
364
365 You can use the screenshot below as a guide to selecting the correct signal
366 and slot.
367
368 \image rgbController-configure-connection2.png {Screenshot showing the
369 configuration to connect the slider with the spinbox, so the slider
370 changes the spinbox value}
371
372 Now that you have successfully connected the objects for the "RED"
373 component of the RGB Controller, do the same for the "GREEN" and "BLUE"
374 components as well.
375
376 Since RGB values range between 0 and 255, we need to limit the spin box
377 and slider to that particular range.
378
379 \table
380 \row
381 \li \inlineimage rgbController-property-editing.png {Screenshot
382 showing option to change minimum and maximum
383 value that can be entered in the spinbox}
384 \li \b{Setting Widget Properties}
385
386 Click on the first spin box. Within the \gui{Property Editor}, you will
387 see \l{QSpinBox}'s properties. Enter "255" for the
388 \l{QSpinBox::}{maximum} property. Then, click on the first vertical
389 slider, you will see \l{QAbstractSlider}'s properties. Enter "255" for
390 the \l{QAbstractSlider::}{maximum} property as well. Repeat this
391 process for the remaining spin boxes and sliders.
392 \endtable
393
394 Now, we preview your form to see how it would look in your application -
395 press \key{Ctrl + R} or select \gui Preview from the \gui Form menu. Try
396 dragging the slider - the spin box will mirror its value too (and vice
397 versa). Also, you can resize it to see how the layouts that are used to
398 manage the child widgets, respond to different window sizes.
399*/
400
401
402/*!
403 \page designer-editing-mode.html
404 \previouspage Getting to Know Qt Widgets Designer
405 \nextpage Using Layouts in Qt Widgets Designer
406
407 \title Qt Widgets Designer's Editing Modes
408
409 \QD provides four editing modes: \l{Qt Widgets Designer's Widget Editing Mode}
410 {Widget Editing Mode}, \l{Qt Widgets Designer's Signals and Slots Editing Mode}
411 {Signals and Slots Editing Mode}, \l{Qt Widgets Designer's Buddy Editing Mode}
412 {Buddy Editing Mode} and \l{Qt Widgets Designer's Tab Order Editing Mode}
413 {Tab Order Editing Mode}. When working with \QD, you will always be in one
414 of these four modes. To switch between modes, simply select it from the
415 \gui{Edit} menu or the toolbar. The table below describes these modes in
416 further detail.
417
418 \table
419 \header \li \li \b{Editing Modes}
420 \row
421 \li \inlineimage designer-widget-tool.png {Designer widget tool icon}
422 \li In \l{Qt Widgets Designer's Widget Editing Mode}{Edit} mode, we can
423 change the appearance of the form, add layouts, and edit the
424 properties of each widget. To switch to this mode, press
425 \key{F3}. This is \QD's default mode.
426
427 \row
428 \li \inlineimage designer-connection-tool.png {\QD connection tool icon}
429 \li In \l{Qt Widgets Designer's Signals and Slots Editing Mode}
430 {Signals and Slots} mode, we can connect widgets together using
431 Qt's signals and slots mechanism. To switch to this mode, press
432 \key{F4}.
433
434 \row
435 \li \inlineimage designer-buddy-tool.png {\QD buddy tool icon}
436 \li In \l{Qt Widgets Designer's Buddy Editing Mode}{Buddy Editing Mode},
437 buddy widgets can be assigned to label widgets to help them
438 handle keyboard focus correctly.
439
440 \row
441 \li \inlineimage designer-tab-order-tool.png {\QD tab order tool icon}
442 \li In \l{Qt Widgets Designer's Tab Order Editing Mode}
443 {Tab Order Editing Mode}, we can set the order in which widgets
444 receive the keyboard focus.
445 \endtable
446
447*/
448
449
450/*!
451 \page designer-widget-mode.html
452 \previouspage Qt Widgets Designer's Editing Modes
453 \nextpage Qt Widgets Designer's Signals and Slots Editing Mode
454
455 \title Qt Widgets Designer's Widget Editing Mode
456
457 \image designer-editing-mode.png {Screenshot showing the \QD editing
458 mode, to change size or position of a component in a layout}
459
460 In the Widget Editing Mode, objects can be dragged from the main window's
461 widget box to a form, edited, resized, dragged around on the form, and even
462 dragged between forms. Object properties can be modified interactively, so
463 that changes can be seen immediately. The editing interface is intuitive
464 for simple operations, yet it still supports Qt's powerful layout
465 facilities.
466
467
468 To create and edit new forms, open the \gui File menu and select
469 \gui{New Form...} or press \key{Ctrl+N}. Existing forms can also be edited
470 by selecting \gui{Open Form...} from the \gui File menu or pressing
471 \key{Ctrl+O}.
472
473 At any point, you can save your form by selecting the \gui{Save From As...}
474 option from the \gui File menu. The UI files saved by \QD contain
475 information about the objects used, and any details of signal and slot
476 connections between them.
477
478
479 \section1 Editing A Form
480
481 By default, new forms are opened in widget editing mode. To switch to Edit
482 mode from another mode, select \gui{Edit Widgets} from the \gui Edit menu
483 or press the \key F3 key.
484
485 Objects are added to the form by dragging them from the main widget box
486 and dropping them in the desired location on the form. Once there, they
487 can be moved around simply by dragging them, or using the cursor keys.
488 Pressing the \key Ctrl key at the same time moves the selected widget
489 pixel by pixel, while using the cursor keys alone make the selected widget
490 snap to the grid when it is moved. Objects can be selected by clicking on
491 them with the left mouse button. You can also use the \key Tab key to
492 change the selection.
493
494 The widget box contains objects in a number of different categories, all of
495 which can be placed on the form as required. The only objects that require
496 a little more preparation are the \gui Container widgets. These are
497 described in further detail in the \l{Using Containers in Qt Widgets Designer}
498 chapter.
499
500
501 \target SelectingObjects
502 \table
503 \row
504 \li \inlineimage designer-selecting-widget.png {Screenshot showing
505 a widget that is selected in \QD editor mode}
506 \li \b{Selecting Objects}
507
508 Objects on the form are selected by clicking on them with the left
509 mouse button. When an object is selected, resize handles are shown at
510 each corner and the midpoint of each side, indicating that it can be
511 resized.
512
513 To select additional objects, hold down the \key Control key and click on
514 them. If more than one object is selected, the current object will be
515 displayed with resize handles of a different color.
516
517 To move a widget within a layout, hold down \key Shift and \key Control
518 while dragging the widget. This extends the selection to the widget's
519 parent layout.
520
521 Alternatively, objects can be selected in the
522 \l{The Object Inspector}{Object Inspector}.
523 \endtable
524
525 When a widget is selected, normal clipboard operations such as cut, copy,
526 and paste can be performed on it. All of these operations can be done and
527 undone, as necessary.
528
529 The following shortcuts can be used:
530
531 \target ShortcutsForEditing
532 \table
533 \header \li Action \li Shortcut \li Description
534 \row
535 \li Cut
536 \li \key{Ctrl+X}
537 \li Cuts the selected objects to the clipboard.
538 \row
539 \li Copy
540 \li \key{Ctrl+C}
541 \li Copies the selected objects to the clipboard.
542 \row
543 \li Paste
544 \li \key{Ctrl+V}
545 \li Pastes the objects in the clipboard onto the form.
546 \row
547 \li Delete
548 \li \key Delete
549 \li Deletes the selected objects.
550 \row
551 \li Clone object
552 \li \key{Ctrl+drag} (leftmouse button)
553 \li Makes a copy of the selected object or group of objects.
554 \row
555 \li Preview
556 \li \key{Ctrl+R}
557 \li Shows a preview of the form.
558 \endtable
559
560 All of the above actions (apart from cloning) can be accessed via both the
561 \gui Edit menu and the form's context menu. These menus also provide
562 funcitons for laying out objects as well as a \gui{Select All} function to
563 select all the objects on the form.
564
565 Widgets are not unique objects; you can make as many copies of them as you
566 need. To quickly duplicate a widget, you can clone it by holding down the
567 \key Ctrl key and dragging it. This allows widgets to be copied and placed
568 on the form more quickly than with clipboard operations.
569
570
571 \target DragAndDrop
572 \table
573 \row
574 \li \inlineimage designer-dragging-onto-form.png {Screenshot showing
575 widgets in the ui editor that can be moved freely
576 by using drag and drop}
577 \li \b{Drag and Drop}
578
579 \QD makes extensive use of the drag and drop facilities provided by Qt.
580 Widgets can be dragged from the widget box and dropped onto the form.
581
582 Widgets can also be "cloned" on the form: Holding down \key Ctrl and
583 dragging the widget creates a copy of the widget that can be dragged to
584 a new position.
585
586 It is also possible to drop Widgets onto the \l {The Object Inspector}
587 {Object Inspector} to handle nested layouts easily.
588 \endtable
589
590 \QD allows selections of objects to be copied, pasted, and dragged between
591 forms. You can use this feature to create more than one copy of the same
592 form, and experiment with different layouts in each of them.
593
594
595 \section2 The Property Editor
596
597 The Property Editor always displays properties of the currently selected
598 object on the form. The available properties depend on the object being
599 edited, but all of the widgets provided have common properties such as
600 \l{QObject::}{objectName}, the object's internal name, and
601 \l{QWidget::}{enabled}, the property that determines whether an
602 object can be interacted with or not.
603
604
605 \target EditingProperties
606 \table
607 \row
608 \li \inlineimage designer-property-editor.png {Screenshot showing
609 the property editor of a widget with options to
610 freely change the widget as desired}
611 \li \b{Editing Properties}
612
613 The property editor uses standard Qt input widgets to manage the
614 properties of objects on the form. Textual properties are shown in line
615 edits, integer properties are displayed in spinboxes, boolean
616 properties are displayed in check boxes, and compound properties such
617 as colors and sizes are presented in drop-down lists of input widgets.
618
619 Modified properties are indicated with bold labels. To reset them, click
620 the arrow button on the right.
621
622 Changes in properties are applied to all selected objects that have the
623 same property.
624 \endtable
625
626 Certain properties are treated specially by the property editor:
627
628 \list
629 \li Compound properties -- properties that are made up of more than one
630 value -- are represented as nodes that can be expanded, allowing
631 their values to be edited.
632 \li Properties that contain a choice or selection of flags are edited
633 via combo boxes with checkable items.
634 \li Properties that allow access to rich data types, such as QPalette,
635 are modified using dialogs that open when the properties are edited.
636 QLabel and the widgets in the \gui Buttons section of the widget box
637 have a \c text property that can also be edited by double-clicking
638 on the widget or by pressing \gui F2. \QD interprets the backslash
639 (\\‍) character specially, enabling newline (\\n) characters to be
640 inserted into the text; the \\\\ character sequence is used to
641 insert a single backslash into the text. A context menu can also be
642 opened while editing, providing another way to insert special
643 characters and newlines into the text.
644 \endlist
645
646
647 \section2 Dynamic Properties
648
649 The property editor can also be used to add new
650 \l{QObject#Dynamic Properties}{dynamic properties} to both standard Qt
651 widgets and to forms themselves. Since Qt 4.4, dynamic properties are added
652 and removed via the property editor's toolbar, shown below.
653
654 \image designer-property-editor-toolbar.png {Screenshot showing the property
655 editor toolbar for a widget}
656
657 To add a dynamic property, click on the \gui Add button
658 \inlineimage designer-property-editor-add-dynamic.png {Add button}
659 . To remove it, click on the \gui Remove button
660 \inlineimage designer-property-editor-remove-dynamic.png {Remove button}
661 instead. You can also sort the properties alphabetically and change the
662 color groups by clickinig on the \gui Configure button
663 \inlineimage designer-property-editor-configure.png {Configure button}
664 .
665
666 \section2 The Object Inspector
667 \table
668 \row
669 \li \inlineimage designer-object-inspector.png {Screenshot showing
670 an object tree of all widgets in the layout}
671 \li \b{The Object Inspector}
672
673 The \gui{Object Inspector} displays a hierarchical list of all the
674 objects on the form that is currently being edited. To show the child
675 objects of a container widget or a layout, click the handle next to the
676 object label.
677
678 Each object on a form can be selected by clicking on the corresponding
679 item in the \gui{Object Inspector}. Right-clicking opens the form's
680 context menu. These features can be useful if you have many overlapping
681 objects. To locate an object in the \gui{Object Inspector}, use
682 \key{Ctrl+F}.
683
684 Since Qt 4.4, double-clicking on the object's name allows you to change
685 the object's name with the in-place editor.
686
687 Since Qt 4.5, the \gui{Object Inspector} displays the layout state of
688 the containers. The broken layout icon ###ICON is displayed if there is
689 something wrong with the layouts.
690
691 \endtable
692*/
693
694
695/*!
696 \page designer-layouts.html
697 \previouspage Qt Widgets Designer's Widget Editing Mode
698 \nextpage Qt Widgets Designer's Signals and Slots Editing Mode
699
700 \title Using Layouts in Qt Widgets Designer
701
702 Before a form can be used, the objects on the form need to be placed into
703 layouts. This ensures that the objects will be displayed properly when the
704 form is previewed or used in an application. Placing objects in a layout
705 also ensures that they will be resized correctly when the form is resized.
706
707 Once widgets have been inserted into a layout, it is not possible to move
708 and resize them individually because the layout itself controls the
709 geometry of each widget within it, taking account of the hints provided by
710 spacers. Spacers can be added to the layout to influence the geometries of
711 the widgets.
712
713 Layouts can be nested to form a hierarchy. For example, to achieve a
714 typical dialog layout with a horizontal row of buttons, the dialog
715 elements can be laid out using a vertical box layout with a horizontal
716 box layout containing the buttons at the bottom. For an introduction to
717 the Qt layout system, refer to \l{Layout Management}.
718
719 To break a layout, press \key{Ctrl+0} or choose \gui{Break Layout} from
720 the form's context menu, the \gui Form menu or the main toolbar.
721
722 \section1 Setting A Top Level Layout
723
724 The form's top level layout can be set by clearing the selection (click the
725 left mouse button on the form itself) and applying a layout. A top level
726 layout is necessary to ensure that your widgets will resize correctly when
727 its window is resized. To check if you have set a top level layout, preview
728 your widget and attempt to resize the window by dragging the size grip.
729
730 \table
731 \row
732 \li \inlineimage designer-set-layout.png {Screenshot showing buttons
733 to change the layout type}
734 \li \b{Applying a Layout}
735
736 To apply a layout, you can select your choice of layout from the
737 toolbar shown on the left, or from the context menu shown below.
738 \endtable
739
740 Similary, top level layouts are set on container widgets (QGroupBox)
741 or on pages of page-based container widgets (QTabWidget, QToolBox
742 and QStackedWidget), respectively. The container widget needs to be
743 selected for this to succeed.
744
745 Top level layouts are not visible as separate objects in the Object
746 Inspector. Their properties appear below the widget properties of the
747 main form, container widget, or page of a container widget in the
748 Property Editor.
749
750 \image designer-set-layout2.png {Screenshot showing another option
751 to change layout type by right clicking in the editor}
752
753
754 \section1 Layout Objects
755
756 Layout objects are created by applying a layout to a group of
757 existing objects. This is achieved by selecting the objects that you need
758 to manage and applying one of the standard layouts using the main toolbar,
759 the \gui Form menu, or the form's context menu.
760
761 The layout object is indicated by a red frame on the form and appears as
762 an object in the Object Inspector. Its properties (margins and constraints)
763 are shown in the Property Editor.
764
765 The layout object can be selected and placed within another layout along
766 with other widgets and layout objects to build a layout hierarchy.
767
768 When a child layout object is selected, its parent layout object can be
769 selected by pressing down the \key Shift key while clicking on it. This
770 makes it possible to select a specific layout in a hierarchy, which is
771 otherwise difficult due to the small frame.
772
773
774 \section1 Inserting Objects Into a Layout
775 \target InsertingObjectsIntoALayout
776
777 Objects can be inserted into an existing layout by dragging them from
778 their current positions and dropping them at the required location. A
779 blue cursor is displayed in the layout as an object is dragged over
780 it to indicate where the object will be added.
781
782 \image designer-layout-inserting.png {Screenshot showing how to move
783 widgets in a layout with drag and drop}
784 \caption Inserting Objects into a Layout
785
786 \section1 Layout Types
787 \section2 Horizontal and Vertical (Box) Layouts
788
789 The simplest way to arrange objects on a form is to place them in a
790 horizontal or vertical layout. Horizontal layouts ensure that the widgets
791 within are aligned horizontally; vertical layouts ensure that they are
792 aligned vertically.
793
794 Horizontal and vertical layouts can be combined and nested to any depth.
795 However, if you need more control over the placement of objects, consider
796 using the grid layout.
797
798
799 \section2 The Grid Layout
800
801 Complex form layouts can be created by placing objects in a grid layout.
802 This kind of layout gives the form designer much more freedom to arrange
803 widgets on the form, but can result in a much less flexible layout.
804 However, for some kinds of form layout, a grid arrangement is much more
805 suitable than a nested arrangement of horizontal and vertical layouts.
806
807
808 \section2 The Form Layout
809
810 The QFormLayout
811 class manages widgets in a two-column form; the left column holds labels
812 and the right column holds field widgets such as line edits, spin boxes,
813 etc. The QFormLayout class adheres to various platform look and feel
814 guidelines and supports wrapping for long rows.
815
816 \image designer-form-layout.png {Screenshot showing a layout example with
817 two labels and on each label a text field on the side}
818
819 The UI file above results in the previews shown below.
820
821 \table
822 \header
823 \li Windows XP
824 \li \macos
825 \li Cleanlooks
826 \row
827 \li \inlineimage designer-form-layout-windowsXP.png {Screenshot
828 showing the layout preview on Windows XP}
829 \li \inlineimage designer-form-layout-macintosh.png {Screenshot
830 showing the layout preview on \macos}
831 \li \inlineimage designer-form-layout-cleanlooks.png {Screenshot
832 showing the layout preview with clean looks on
833 Windows XP}
834 \endtable
835
836
837 \section2 Splitter Layouts
838
839 Another common way to manage the layout of objects on a form is to place
840 them in a splitter. These splitters arrange the objects horizontally or
841 vertically in the same way as normal layouts, but also allow the user to
842 adjust the amount of space allocated to each object.
843
844 \image designer-splitter-layout.png {Screenshot showing to change layout
845 to "Lay Out Vertically in Splitter"}
846
847 Although QSplitter is a container widget, \QD treats splitter objects as
848 layouts that are applied to existing widgets. To place a group of widgets
849 into a splitter, select them
850 \l{Qt Widgets Designer's Widget Editing Mode#SelectingObjects}{as described here}
851 then apply the splitter layout by using the appropriate toolbar button,
852 keyboard shortcut, or \gui{Lay out} context menu entry.
853
854
855 \section1 Shortcut Keys
856
857 In addition to the standard toolbar and context menu entries, there is also
858 a set of keyboard shortcuts to apply layouts on widgets.
859
860 \target LayoutShortcuts
861 \table
862 \header
863 \li Layout
864 \li Shortcut
865 \li Description
866 \row
867 \li Horizontal
868 \li \key{Ctrl+1}
869 \li Places the selected objects in a horizontal layout.
870 \row
871 \li Vertical
872 \li \key{Ctrl+2}
873 \li Places the selected objects in a vertical layout.
874 \row
875 \li Grid
876 \li \key{Ctrl+5}
877 \li Places the selected objects in a grid layout.
878 \row
879 \li Form
880 \li \key{Ctrl+6}
881 \li Places the selected objects in a form layout.
882 \row
883 \li Horizontal splitter
884 \li \key{Ctrl+3}
885 \li Creates a horizontal splitter and places the selected objects
886 inside it.
887 \row
888 \li Vertical splitter
889 \li \key{Ctrl+4}
890 \li Creates a vertical splitter and places the selected objects
891 inside it.
892 \row
893 \li Adjust size
894 \li \key{Ctrl+J}
895 \li Adjusts the size of the layout to ensure that each child object
896 has sufficient space to display its contents. See
897 QWidget::adjustSize() for more information.
898 \endtable
899
900 \note \key{Ctrl+0} is used to break a layout.
901
902*/
903
904
905/*!
906 \page designer-preview.html
907 \previouspage Using Layouts in Qt Widgets Designer
908 \nextpage Qt Widgets Designer's Buddy Editing Mode
909 \title Saving, Previewing and Printing Forms in Qt Widgets Designer
910
911 Although \QD's forms are accurate representations of the components being
912 edited, it is useful to preview the final appearance while editing. This
913 feature can be activated by opening the \gui Form menu and selecting
914 \gui Preview, or by pressing \key{Ctrl+R} when in the form.
915
916 \image designer-dialog-preview.png {Screenshot showing a preview of a layout
917 to create an image with options to change name, width, height, and
918 color depth}
919
920 The preview shows exactly what the final component will look like when used
921 in an application.
922
923 Since Qt 4.4, it is possible to preview forms with various skins - default
924 skins, skins created with Qt Style Sheets or device skins. This feature
925 simulates the effect of calling \c{QApplication::setStyleSheet()} in the
926 application.
927
928 To preview your form with skins, open the \gui Edit menu and select
929 \gui{Preferences...}
930
931 You will see the dialog shown below:
932
933 \image designer-preview-style.png {Screenshot of preferences dialog showing
934 options for interface mode, font settings, print and preview
935 configuration, additional template paths, and grid visibility
936 and snapping}
937
938 The \gui{Print/Preview Configuration} checkbox must be checked to activate
939 previews of skins. You can select the styles provided from the \gui{Style}
940 drop-down box.
941
942 \image designer-preview-style-selection.png {Screenshot of \QD print
943 and preview configuration section showing a dropdown menu for selecting
944 interface styles, including Default, Windows, WindowsXP etc.}
945
946 Alternatively, you can preview custom style sheet created with Qt Style
947 Sheets. The figure below shows an example of Qt Style Sheet syntax and the
948 corresponding output.
949
950 \image designer-preview-stylesheet.png {Screenshot of \QD dialogs
951 showing the Edit Style Sheet window with QLineEdit CSS properties
952 and the Create Image dialog for defining image name, size, and color
953 depth}
954
955 Another option would be to preview your form with device skins. A list of
956 generic device skins are available in \QD, however, you may also use
957 other QVFB skins with the \gui{Browse...} option.
958
959 \image designer-preview-deviceskin-selection.png {Screenshot of \QD
960 print and preview configuration showing a dropdown menu for selecting
961 device skins}
962
963
964 \section1 Viewing the Form's Code
965
966 Since Qt 4.4, it is possible to view code generated by the User Interface
967 Compiler (uic) for the \QD form.
968
969 \image designer-form-viewcode.png {Screenshot showing option to view
970 the layout in code under the drop down menu of "Forms"}
971
972 Select \gui{View Code...} from the \gui{Form} menu and a dialog with the
973 generated code will be displayed. The screenshot below is an example of
974 code generated by the \c{uic}.
975
976 \image designer-code-viewer.png {Screenshot showing a code of "Form" in a
977 code viewer}
978
979 \section1 Saving and Printing the Form
980
981 Forms created in \QD can be saved to an image or printed.
982
983 \table
984 \row
985 \li \inlineimage designer-file-menu.png {Screenshot showing file menu options}
986 \li \b{Saving Forms}
987
988 To save a form as an image, choose the \gui{Save Image...} option. The file
989 will be saved in \c{.png} format.
990
991 \b{Printing Forms}
992
993 To print a form, select the \gui{Print...} option.
994
995 \endtable
996*/
997
998
999/*!
1000 \page designer-connection-mode.html
1001 \previouspage Using Layouts in Qt Widgets Designer
1002 \nextpage Qt Widgets Designer's Buddy Editing Mode
1003
1004
1005 \title Qt Widgets Designer's Signals and Slots Editing Mode
1006
1007 \image designer-connection-mode.png {Screenshot of \QD connection mode
1008 showing the connection of signals between two widgets}
1009
1010 In \QD's signals and slots editing mode, you can connect objects in a form
1011 together using Qt's signals and slots mechanism. Both widgets and layouts
1012 can be connected via an intuitive connection interface, using the menu of
1013 compatible signals and slots provided by \QD. When a form is saved, all
1014 connections are preserved so that they will be ready for use when your
1015 project is built.
1016
1017
1018 For more information on Qt's signals and sltos mechanism, refer to the
1019 \l{Signals and Slots} document.
1020
1021
1022 \section1 Connecting Objects
1023
1024 To begin connecting objects, enter the signals and slots editing mode by
1025 opening the \gui Edit menu and selecting \gui{Edit Signals/Slots}, or by
1026 pressing the \key F4 key.
1027
1028 All widgets and layouts on the form can be connected together. However,
1029 spacers just provide spacing hints to layouts, so they cannot be connected
1030 to other objects.
1031
1032
1033 \target HighlightedObjects
1034 \table
1035 \row
1036 \li \inlineimage designer-connection-highlight.png {Screenshot
1037 showing a widget of a layout that is highlighted}
1038 \li \b{Highlighted Objects}
1039
1040 When the cursor is over an object that can be used in a connection, the
1041 object will be highlighted.
1042 \endtable
1043
1044 To make a connectionn, press the left mouse button and drag the cursor
1045 towards the object you want to connect it to. As you do this, a line will
1046 extend from the source object to the cursor. If the cursor is over another
1047 object on the form, the line will end with an arrow head that points to the
1048 destination object. This indicates that a connection will be made between
1049 the two objects when you release the mouse button.
1050
1051 You can abandon the connection at any point while you are dragging the
1052 connection path by pressing \key{Esc}.
1053
1054 \target MakingAConnection
1055 \table
1056 \row
1057 \li \inlineimage designer-connection-making.png {Screenshot showin
1058 how to connect one widget to another by pressing
1059 left click to the desired widget that should be
1060 connected to}
1061 \li \b{Making a Connection}
1062
1063 The connection path will change its shape as the cursor moves around
1064 the form. As it passes over objects, they are highlighted, indicating
1065 that they can be used in a signal and slot connection. Release the
1066 mouse button to make the connection.
1067 \endtable
1068
1069 The \gui{Configure Connection} dialog (below) is displayed, showing signals
1070 from the source object and slots from the destination object that you can
1071 use.
1072
1073 \image designer-connection-dialog.png {Screenshot of window listing signals
1074 that can be emitted between two selected widgets}
1075
1076 To complete the connection, select a signal from the source object and a
1077 slot from the destination object, then click \key OK. Click \key Cancel if
1078 you wish to abandon the connection.
1079
1080 \note If the \gui{Show all signals and slots} checkbox is selected, all
1081 available signals from the source object will be shown. Otherwise, the
1082 signals and slots inherited from QWidget will be hidden.
1083
1084 You can make as many connections as you like between objects on the form;
1085 it is possible to connect signals from objects to slots in the form itself.
1086 As a result, the signal and slot connections in many dialogs can be
1087 completely configured from within \QD.
1088
1089 \target ConnectingToTheForm
1090 \table
1091 \row
1092 \li \inlineimage designer-connection-to-form.png {Screenshot showing
1093 an arrow coming from a widget following the cursor
1094 to choose a widget that receives the signals}
1095 \li \b{Connecting to a Form}
1096
1097 To connect an object to the form itself, simply position the cursor
1098 over the form and release the mouse button. The end point of the
1099 connection changes to the electrical "ground" symbol.
1100 \endtable
1101
1102
1103 \section1 Editing and Deleting Connections
1104
1105 By default, connection paths are created with two labels that show the
1106 signal and slot involved in the connection. These labels are usually
1107 oriented along the line of the connection. You can move them around inside
1108 their host widgets by dragging the red square at each end of the connection
1109 path.
1110
1111 \target ConnectionEditor
1112 \table
1113 \row
1114 \li \inlineimage designer-connection-editor.png {Screenshot of Qt
1115 Designer Signal and Slot editor showing connections
1116 between an okButton and a cancelButton where the
1117 okButton and cancelbutton send a "clicked()" signal.
1118 The okButton triggers the "accept()" function and
1119 the cancelButton "reject()"}
1120 \li \b{The Signal/Slot Editor}
1121
1122 The signal and slot used in a connection can be changed after it has
1123 been set up. When a connection is configured, it becomes visible in
1124 \QD's signal and slot editor where it can be further edited. You can
1125 also edit signal/slot connections by double-clicking on the connection
1126 path or one of its labels to display the Connection Dialog.
1127 \endtable
1128
1129 \target DeletingConnections
1130 \table
1131 \row
1132 \li \inlineimage designer-connection-editing.png {Screenshot
1133 showing connection edit mode to change the
1134 signals between two widgets}
1135 \li \b{Deleting Connections}
1136
1137 The whole connection can be selected by clicking on any of its path
1138 segments. Once selected, a connection can be deleted with the
1139 \key Delete key, ensuring that it will not be set up in the UI
1140 file.
1141 \endtable
1142*/
1143
1144
1145/*!
1146 \page designer-buddy-mode.html
1147 \previouspage Qt Widgets Designer's Signals and Slots Editing Mode
1148 \nextpage Qt Widgets Designer's Tab Order Editing Mode
1149
1150 \title Qt Widgets Designer's Buddy Editing Mode
1151
1152 \image designer-buddy-mode.png {Screenshot of buddy mode showing which widget
1153 are bindet together}
1154
1155 One of the most useful basic features of Qt is the support for buddy
1156 widgets. A buddy widget accepts the input focus on behalf of a QLabel when
1157 the user types the label's shortcut key combination. The buddy concept is
1158 also used in Qt's \l{Model/View Programming}{model/view} framework.
1159
1160
1161 \section1 Linking Labels to Buddy Widgets
1162
1163 To enter buddy editing mode, open the \gui Edit menu and select
1164 \gui{Edit Buddies}. This mode presents the widgets on the form in a similar
1165 way to \l{Qt Widgets Designer's Signals and Slots Editing Mode}{signals and slots
1166 editing mode} but in this mode, connections must start at label widgets.
1167 Ideally, you should connect each label widget that provides a shortcut with
1168 a suitable input widget, such as a QLineEdit.
1169
1170
1171 \target MakingBuddies
1172 \table
1173 \row
1174 \li \inlineimage designer-buddy-making.png {Screenshot showing how to
1175 bind widgets by pressing on one widget and move the
1176 cursor to the other widget that should be bindet to}
1177 \li \b{Making Buddies}
1178
1179 To define a buddy widget for a label, click on the label, drag the
1180 connection to another widget on the form, and release the mouse button.
1181 The connection shown indicates how input focus is passed to the buddy
1182 widget. You can use the form preview to test the connections between
1183 each label and its buddy.
1184 \endtable
1185
1186
1187 \section1 Removing Buddy Connections
1188
1189 Only one buddy widget can be defined for each label. To change the buddy
1190 used, it is necessary to delete any existing buddy connection before you
1191 create a new one.
1192
1193 Connections between labels and their buddy widgets can be deleted in the
1194 same way as signal-slot connections in signals and slots editing mode:
1195 Select the buddy connection by clicking on it and press the \key Delete
1196 key. This operation does not modify either the label or its buddy in any
1197 way.
1198*/
1199
1200
1201/*!
1202 \page designer-tab-order.html
1203 \previouspage Qt Widgets Designer's Buddy Editing Mode
1204 \nextpage Using Containers in Qt Widgets Designer
1205
1206 \title Qt Widgets Designer's Tab Order Editing Mode
1207
1208 \image designer-tab-order-mode.png {Screenshot showing the order of the
1209 layout highlighting in which order the sections of the application
1210 should be used}
1211
1212 Many users expect to be able to navigate between widgets and controls
1213 using only the keyboard. Qt lets the user navigate between input widgets
1214 with the \key Tab and \key{Shift+Tab} keyboard shortcuts. The default
1215 \e{tab order} is based on the order in which widgets are constructed.
1216 Although this order may be sufficient for many users, it is often better
1217 to explicitly specify the tab order to make your application easier to
1218 use.
1219
1220
1221 \section1 Setting the Tab Order
1222
1223 To enter tab order editing mode, open the \gui Edit menu and select
1224 \gui{Edit Tab Order}. In this mode, each input widget in the form is shown
1225 with a number indicating its position in the tab order. So, if the user
1226 gives the first input widget the input focus and then presses the tab key,
1227 the focus will move to the second input widget, and so on.
1228
1229 The tab order is defined by clicking on each of the numbers in the correct
1230 order. The first number you click will change to red, indicating the
1231 currently edited position in the tab order chain. The widget associated
1232 with the number will become the first one in the tab order chain. Clicking
1233 on another widget will make it the second in the tab order, and so on.
1234
1235 Repeat this process until you are satisfied with the tab order in the form
1236 -- you do not need to click every input widget if you see that the
1237 remaining widgets are already in the correct order. Numbers, for which you
1238 already set the order, change to green, while those which are not clicked
1239 yet, remain blue.
1240
1241 If you make a mistake, simply double click outside of any number or choose
1242 \gui{Restart} from the form's context menu to start again. If you have many
1243 widgets on your form and would like to change the tab order in the middle or
1244 at the end of the tab order chain, you can edit it at any position. Press
1245 \key{Ctrl} and click the number from which you want to start.
1246 Alternatively, choose \gui{Start from Here} in the context menu.
1247
1248*/
1249
1250
1251/*!
1252 \page designer-using-containers.html
1253 \previouspage Qt Widgets Designer's Tab Order Editing Mode
1254 \nextpage Creating Main Windows in Qt Widgets Designer
1255
1256
1257 \title Using Containers in Qt Widgets Designer
1258
1259 Container widgets provide high level control over groups of objects on a
1260 form. They can be used to perform a variety of functions, such as managing
1261 input widgets, providing paged and tabbed layouts, or just acting as
1262 decorative containers for other objects.
1263
1264 \image designer-widget-morph.png {Screenshot showing the "Morph into" options
1265 for a button. It shows option to morph into QCheckbox, QRadioButton,
1266 QToolButton, and QCommandLinkButton}
1267
1268 \QD provides visual feedback to help you place objects inside your
1269 containers. When you drag an object from the widget box (or elsewhere) on
1270 the form, each container will be highlighted when the cursor is positioned
1271 over it. This indicates that you can drop the object inside, making it a
1272 child object of the container. This feedback is important because it is
1273 easy to place objects close to containers without actually placing them
1274 inside. Both widgets and spacers can be used inside containers.
1275
1276 Stacked widgets, tab widgets, and toolboxes are handled specially in \QD.
1277 Normally, when adding pages (tabs, pages, compartments) to these containers
1278 in your own code, you need to supply existing widgets, either as
1279 placeholders or containing child widgets. In \QD, these are automatically
1280 created for you, so you can add child objects to each page straight away.
1281
1282 Each container typically allows its child objects to be arranged in one or
1283 more layouts. The type of layout management provided depends on each
1284 container, although setting the layout is usually just a matter of
1285 selecting the container by clicking it, and applying a layout. The table
1286 below shows a list of available containers.
1287
1288 \table
1289 \row
1290 \li \inlineimage designer-containers-frame.png {Screenshot showing
1291 a frame that is selected}
1292 \li \b Frames
1293
1294 Frames are used to enclose and group widgets, as well as to provide
1295 decoration. They are used as the foundation for more complex
1296 containers, but they can also be used as placeholders in forms.
1297
1298 The most important properties of frames are \c frameShape,
1299 \c frameShadow, \c lineWidth, and \c midLineWidth. These are described
1300 in more detail in the QFrame class description.
1301
1302 \row
1303 \li \inlineimage designer-containers-groupbox.png {Screenshot
1304 showing a group box, including multiple widgets,
1305 that is selected}
1306 \li \b{Group Boxes}
1307
1308 Group boxes are usually used to group together collections of
1309 checkboxes and radio buttons with similar purposes.
1310
1311 Among the significant properties of group boxes are \c title, \c flat,
1312 \c checkable, and \c checked, as described in the \l QGroupBox
1313 class documentation. Each group box can contain its own layout, and
1314 this is necessary if it contains other widgets. To add a layout to the
1315 group box, click inside it and apply the layout as usual.
1316
1317 \row
1318 \li \inlineimage designer-containers-stackedwidget.png {Screenshot
1319 showing group box containing widgets that are
1320 stacked on on of each other}
1321 \li \b{Stacked Widgets}
1322
1323 Stacked widgets are collections of widgets in which only the topmost
1324 layer is visible. Control over the visible layer is usually managed by
1325 another widget, such as combobox, using signals and slots.
1326
1327 \QD shows arrows in the top-right corner of the stack to allow you to
1328 see all the widgets in the stack when designing it. These arrows do not
1329 appear in the preview or in the final component. To navigate between
1330 pages in the stack, select the stacked widget and use the
1331 \gui{Next Page} and \gui{Previous Page} entries from the context menu.
1332 The \gui{Insert Page} and \gui{Delete Page} context menu options allow
1333 you to add and remove pages.
1334
1335 \row
1336 \li \inlineimage designer-containers-tabwidget.png {Screenshot showing
1337 a tab widget in a container}
1338 \li \b{Tab Widgets}
1339
1340 Tab widgets allow the developer to split up the contents of a widget
1341 into different labelled sections, only one of which is displayed at any
1342 given time. By default, the tab widget contains two tabs, and these can
1343 be deleted or renamed as required. You can also add additional tabs.
1344
1345 To delete a tab:
1346 \list
1347 \li Click on its label to make it the current tab.
1348 \li Select the tab widget and open its context menu.
1349 \li Select \gui{Delete Page}.
1350 \endlist
1351
1352 To add a new tab:
1353 \list
1354 \li Select the tab widget and open its context menu.
1355 \li Select \gui{Insert Page}.
1356 \li You can add a page before or after the \e current page. \QD
1357 will create a new widget for that particular tab and insert it
1358 into the tab widget.
1359 \li You can set the title of the current tab by changing the
1360 \c currentTabText property in the \gui{Property Editor}.
1361 \endlist
1362
1363 \row
1364 \li \inlineimage designer-containers-toolbox.png {Screensshot showing
1365 a toolbox in a container}
1366 \li \b{ToolBox Widgets}
1367
1368 Toolbox widgets provide a series of pages or compartments in a toolbox.
1369 They are handled in a way similar to stacked widgets.
1370
1371 To rename a page in a toolbox, make the toolbox your current pange and
1372 change its \c currentItemText property from the \gui{Property Editor}.
1373
1374 To add a new page, select \gui{Insert Page} from the toolbox widget's
1375 context menu. You can add the page before or after the current page.
1376
1377 To delete a page, select \gui{Delete Page} from the toolbox widget's
1378 context menu.
1379
1380 \row
1381 \li \inlineimage designer-containers-dockwidget.png {Screenshot
1382 showing a dock widget in a container}
1383 \li \b{Dock Widgets}
1384
1385 Dock widgets are floating panels, often containing input widgets and
1386 more complex controls, that are either attached to the edges of the
1387 main window in "dock areas", or floated as independent tool windows.
1388
1389 Although dock widgets can be added to any type of form, they are
1390 typically used with forms created from the
1391 \l{Creating Main Windows in Qt Widgets Designer}{main window template}.
1392
1393 \endtable
1394*/
1395
1396
1397/*!
1398 \page designer-creating-mainwindows.html
1399 \previouspage Using Containers in Qt Widgets Designer
1400 \nextpage Editing Resources with Qt Widgets Designer
1401
1402 \title Creating Main Windows in Qt Widgets Designer
1403
1404 \QD can be used to create user interfaces for different purposes, and
1405 it provides different kinds of form templates for each user interface. The
1406 main window template is used to create application windows with menu bars,
1407 toolbars, and dock widgets.
1408
1409 \omit
1410 \image designer-mainwindow-example.png
1411 \endomit
1412
1413 Create a new main window by opening the \gui File menu and selecting the
1414 \gui{New Form...} option, or by pressing \key{Ctrl+N}. Then, select the
1415 \gui{Main Window} template. This template provides a main application
1416 window containing a menu bar and a toolbar by default -- these can be
1417 removed if they are not required.
1418
1419 If you remove the menu bar, a new one can be created by selecting the
1420 \gui{Create Menu Bar} option from the context menu, obtained by
1421 right-clicking within the main window form.
1422
1423 An application can have only \b one menu bar, but \b several
1424 toolbars.
1425
1426
1427 \section1 Menus
1428
1429 Menus are added to the menu bar by modifying the \gui{Type Here}
1430 placeholders. One of these is always present for editing purposes, and
1431 will not be displayed in the preview or in the finished window.
1432
1433 Once created, the properties of a menu can be accessed using the
1434 \l{Qt Widgets Designer's Widget Editing Mode#The Property Editor}{Property Editor},
1435 and each menu can be accessed for this purpose via the
1436 \l{Qt Widgets Designer's Widget Editing Mode#The Object Inspector}{The Object Inspector}.
1437
1438 Existing menus can be removed by opening a context menu over the label in
1439 the menu bar, and selecting \gui{Remove Menu 'menu_name'}.
1440
1441
1442 \target CreatingAMenu
1443 \div {class="float-left"}
1444 \inlineimage designer-creating-menu1.png {Screenshot showing cursor hovering over a
1445 button to create a menu on the window}
1446 \inlineimage designer-creating-menu2.png {Screenshot showing cursor clicking on the
1447 button to create a menu on the window}
1448 \br
1449 \inlineimage designer-creating-menu3.png {Screenshot showing a text field that
1450 results when clicking the button to name the menu}
1451 \inlineimage designer-creating-menu4.png {Screenshot showing the newly created menu}
1452 \enddiv
1453
1454 \section2 Creating a Menu
1455
1456 Double-click the placeholder item to begin editing. The menu text,
1457 displayed using a line edit, can be modified.
1458
1459 Insert the required text for the new menu. Inserting an
1460 ampersand character (&) causes the letter following it to be
1461 used as a mnemonic for the menu.
1462
1463 Press \key Return or \key Enter to accept the new text, or press
1464 \key Escape to reject it. You can undo the editing operation later if
1465 required.
1466
1467 \div {class="clear-both"}
1468 \enddiv
1469
1470 Menus can also be rearranged in the menu bar simply by dragging and
1471 dropping them in the preferred location. A vertical red line indicates the
1472 position where the menu will be inserted.
1473
1474 Menus can contain any number of entries and separators, and can be nested
1475 to the required depth. Adding new entries to menus can be achieved by
1476 navigating the menu structure in the usual way.
1477
1478 \target CreatingAMenuEntry
1479 \div {class="float-right"}
1480 \inlineimage designer-creating-menu-entry1.png {Screenshot of cursor
1481 clicking on the new menu showing a dropdown menu with
1482 button to create options or separators to the dropdown
1483 menu}
1484 \inlineimage designer-creating-menu-entry2.png {Screenshot of cursor
1485 clicking on button to add option to the dropdown menu by
1486 writing a name in the textfield}
1487 \br
1488 \inlineimage designer-creating-menu-entry3.png {Screenshot showing the
1489 newly created button on the dropdown menu}
1490 \inlineimage designer-creating-menu-entry4.png {Screehsot of cursor
1491 clicking the button showing an option to create another
1492 button that pops up after clicking}
1493 \enddiv
1494
1495 \section2 Creating a Menu Entry
1496
1497 Double-click the \gui{Type Here} placeholder to begin editing, or
1498 double-click \gui{Add Separator} to insert a new separator line after
1499 the last entry in the menu.
1500
1501 The menu entry's text is displayed using a line edit, and can be
1502 modified.
1503
1504 Insert the required text for the new entry, optionally using
1505 the ampersand character (&) to mark the letter to use as a
1506 mnemonic for the entry.
1507
1508 Press \key Return or \key Enter to accept the new text, or press
1509 \key Escape to reject it. The action created for this menu entry will
1510 be accessible via the \l{#TheActionEditor}{Action Editor}, and any
1511 associated keyboard shortcut can be set there.
1512
1513 \div {class="clear-both"}
1514 \enddiv
1515
1516 Just like with menus, entries can be moved around simply by dragging and
1517 dropping them in the preferred location. When an entry is dragged over a
1518 closed menu, the menu will open to allow it to be inserted there. Since
1519 menu entries are based on actions, they can also be dropped onto toolbars,
1520 where they will be displayed as toolbar buttons.
1521
1522 \section1 Toolbars
1523
1524 \div {class="float-left"}
1525 \inlineimage designer-creating-toolbar.png {Screenshot showing option to
1526 add a tool bar by right clicking on the ui editor}
1527 \enddiv
1528
1529 \section2 Creating and Removing a Toolbar
1530
1531 Toolbars are added to a main window in a similar way to the menu bar:
1532 Select the \gui{Add Tool Bar} option from the form's context menu.
1533 Alternatively, if there is an existing toolbar in the main window, you can
1534 click the arrow on its right end to create a new toolbar.
1535
1536 Toolbars are removed from the form via an entry in the toolbar's context
1537 menu.
1538
1539 \div {class="clear-both"}
1540 \enddiv
1541
1542 \section2 Adding and Removing Toolbar Buttons
1543
1544 Toolbar buttons are created as actions in the
1545 \l{#TheActionEditor}{Action Editor} and dragged onto the toolbar.
1546 Since actions can be represented by menu entries and toolbar buttons,
1547 they can be moved between menus and toolbars.
1548
1549 \div {class="float-right"}
1550 \inlineimage designer-adding-toolbar-action.png {Screenshot showing cursor
1551 adding a toolbar with drag and drop}
1552 \inlineimage designer-removing-toolbar-action.png {Screenshot showing option
1553 to remove toolbar by right clicking on it}
1554 \enddiv
1555
1556 To share an action between a menu and a toolbar, drag its icon from the
1557 action editor to the toolbar rather than from the menu where its entry is
1558 located. See \l{#Adding an Action}{Adding an Action} for more information
1559 about this process.
1560
1561 Toolbar buttons are removed via the toolbar's context menu.
1562
1563 \div {class="clear-both"}
1564 \enddiv
1565
1566 \section1 Actions
1567
1568 With the menu bar and the toolbars in place, it's time to populate them
1569 with actions. New actions for both menus and toolbars are created in the
1570 action editor window, simplifying the creation and management of actions.
1571
1572 \target TheActionEditor
1573 \div {class="float-left"}
1574 \inlineimage designer-action-editor.png {Screenshot of action editor
1575 listing all actions of a toolbar}
1576 \enddiv
1577
1578 \section2 The Action Editor
1579
1580 Enable the action editor by opening the \gui Tools menu, and switching
1581 on the \gui{Action Editor} option.
1582
1583 The action editor allows you to create \gui New actions and \gui Delete
1584 actions. It also provides a search function, \gui Filter, using the
1585 action's text.
1586
1587 \QD's action editor can be viewed in the classic \gui{Icon View} and
1588 \gui{Detailed View}. The screenshot below shows the action editor in
1589 \gui{Detailed View}. You can also copy and paste actions between menus,
1590 toolbars and forms.
1591
1592 \div {class="clear-both"}
1593 \enddiv
1594
1595 \section2 Creating an Action
1596
1597 To create an action, use the action editor's \gui New button, which will
1598 then pop up an input dialog. Provide the new action with a \gui Text --
1599 this is the text that will appear in a menu entry and as the action's
1600 tooltip. The text is also automatically added to an "action" prefix,
1601 creating the action's \gui{Object Name}.
1602
1603 In addition, the dialog provides the option of selecting an \gui Icon for
1604 the action, as well as removing the current icon.
1605
1606 Once the action is created, it can be used wherever actions are applicable.
1607
1608 \div {class="clear-left"}
1609 \enddiv
1610
1611 \target AddingAnAction
1612 \div {class="float-right"}
1613 \inlineimage designer-adding-menu-action.png {Screenshot showing cursor
1614 adding a toolbar with drag and drop}
1615 \inlineimage designer-adding-toolbar-action.png {Screenshot showing option
1616 to remove toolbar by right clicking on it}
1617 \enddiv
1618
1619 \section2 Adding an Action
1620
1621 To add an action to a menu or a toolbar, simply press the left mouse
1622 button over the action in the action editor, and drag it to the
1623 preferred location.
1624
1625 \QD provides highlighted guide lines that tell you where the action
1626 will be added. Release the mouse button to add the action when you have
1627 found the right spot.
1628
1629 \div {class="clear-right"}
1630 \enddiv
1631
1632 \section1 Dock Widgets
1633
1634 Dock widgets are \l{Using Containers in Qt Widgets Designer}{container widgets}
1635 as well. They can be added to a form by dropping them onto the desired
1636 dock area.
1637
1638 \target AddingADockWidget
1639
1640 \div {class="float-left"}
1641 \inlineimage designer-adding-dockwidget.png {Screenshot showing how to add a
1642 dock widget by using drag and drop}
1643 \enddiv
1644
1645 \section2 Adding a Dock Widget
1646
1647 To add a dock widget to a form, drag one from the \gui Containers section
1648 of the widget box, and drop it onto the main form area. Do not add the
1649 dock widget to an existing layout. Instead, open the \gui{Property Editor}
1650 and enable the \gui{docked} property to place it in a dock area.
1651
1652 Note that it is sometimes easier to configure a dock widget if it is added
1653 to a form before a layout is applied to the central widget. For example,
1654 it is possible to undock it and resize it, making it more convenient to
1655 add child widgets.
1656
1657 Dock widgets can be optionally floated as independent tool windows.
1658 Hence, it is useful to give them window titles by setting their
1659 \l{QDockWidget::}{windowTitle} property. This also helps to identify them on the
1660 form.
1661
1662 \div {class="clear-both"}
1663 \enddiv
1664*/
1665
1666
1667/*!
1668 \page designer-resources.html
1669 \previouspage Creating Main Windows in Qt Widgets Designer
1670 \nextpage Using Stylesheets with Qt Widgets Designer
1671
1672 \title Editing Resources with Qt Widgets Designer
1673
1674 \image designer-resources-editing.png {Screenshot of Edit Resources
1675 dialog showing a resource file containing two image entries}
1676
1677 \QD fully supports the \l{The Qt Resource System}{Qt Resource System},
1678 enabling resources to be specified together with forms as they are
1679 designed. To aid designers and developers manage resources for their
1680 applications, \QD's resource editor allows resources to be defined on a
1681 per-form basis. In other words, each form can have a separate resource
1682 file.
1683
1684 \section1 Defining a Resource File
1685
1686 To specify a resource file you must enable the resource editor by opening
1687 the \gui Tools menu, and switching on the \gui{Resource Browser} option.
1688
1689 \target ResourceFiles
1690 \table
1691 \row
1692 \li \inlineimage designer-resource-browser.png {Screenshot of the
1693 "Resource Browser" window showing the resource
1694 root directory}
1695 \li \b{Resource Files}
1696
1697 Within the resource browser, you can open existing resource files or
1698 create new ones. Click the \gui{Edit Resources} button
1699 \inlineimage designer-edit-resources-button.png {Edit button}
1700 to edit your resources. To reload resources, click on the \gui Reload
1701 button
1702 \inlineimage designer-reload-resources-button.png {Reload resources
1703 button}
1704 .
1705 \endtable
1706
1707
1708 Once a resource file is loaded, you can create or remove entries in it
1709 using the given \gui{Add Files}
1710 \inlineimage designer-add-resource-entry-button.png {Add resource entry button}
1711 and \gui{Remove Files}
1712 \inlineimage designer-remove-resource-entry-button.png {Remove resource entry button}
1713 buttons, and specify resources (e.g., images) using the \gui{Add Files}
1714 button
1715 \inlineimage designer-add-files-button.png {Add files button}
1716 . Note that these resources must reside within the current resource file's
1717 directory or one of its subdirectories.
1718
1719
1720 \target EditResource
1721 \table
1722 \row
1723 \li \inlineimage designer-edit-resource.png {Screenshot of Edit Resources
1724 dialog showing a resource file with a single prefix entry
1725 labeled newPrefix}
1726 \li \b{Editing Resource Files}
1727
1728 Press the
1729 \inlineimage designer-add-resource-entry-button.png {Add resource entry
1730 button}
1731 button to add a new resource entry to the file. Then use the
1732 \gui{Add Files} button
1733 \inlineimage designer-add-files-button.png {Add files button}
1734 to specify the resource.
1735
1736 You can remove resources by selecting the corresponding entry in the
1737 resource editor, and pressing the
1738 \inlineimage designer-remove-resource-entry-button.png {Remove resource entry
1739 button}
1740 button.
1741 \endtable
1742
1743
1744 \section1 Using the Resources
1745
1746 Once the resources are defined you can use them actively when composing
1747 your form. For example, you might want to create a tool button using an
1748 icon specified in the resource file.
1749
1750 \target UsingResources
1751 \table
1752 \row
1753 \li \inlineimage designer-resources-using.png {Screenshot of property
1754 editor showing the icon property with different states,
1755 Normal Off, Normal On and Disabled Off and the option
1756 to choose an image resource}
1757 \li \b{Using Resources}
1758
1759 When changing properties with values that may be defined within a
1760 resource file, \QD's property editor allows you to specify a resource
1761 in addition to the option of selecting a source file in the ordinary
1762 way.
1763
1764 \row
1765 \li \inlineimage designer-resource-selector.png {Screenshot of "Select
1766 Resource" window showing an option to choose which
1767 image should be used as a resource}
1768 \li \b{Selecting a Resource}
1769
1770 You can open the resource selector by clicking \gui{Choose Resource...}
1771 to add resources any time during the design process.
1772
1773\omit
1774... check with Friedemann
1775To quickly assign icon pixmaps to actions or pixmap properties, you may
1776drag the pixmap from the resource editor to the action editor, or to the
1777pixmap property in the property editor.
1778\endomit
1779
1780 \endtable
1781*/
1782
1783
1784/*!
1785 \page designer-stylesheet.html
1786 \previouspage Editing Resources with Qt Widgets Designer
1787 \nextpage Using a Designer UI File in Your C++ Application
1788
1789 \title Using Stylesheets with Qt Widgets Designer
1790
1791 Since Qt 4.2, it is possible to edit stylesheets in \QD with the stylesheet
1792 editor.
1793
1794 \target UsingStylesheets
1795 \table
1796 \row
1797 \li \inlineimage designer-stylesheet-options.png {Screenshot of form editor
1798 showing a label and line editor with the option
1799 highlighted to change stylesheet from the
1800 context menu}
1801 \b{Setting a Stylesheet}
1802
1803 The stylesheet editor can be accessed by right-clicking a widget
1804 and selecting \gui{Change styleSheet...}
1805
1806 \row
1807 \li \inlineimage designer-stylesheet-usage.png {Screenshot showing the
1808 preview of used stylesheet}
1809 \endtable
1810
1811*/
1812
1813
1814/*!
1815 \page designer-using-a-ui-file.html
1816 \previouspage Using Stylesheets with Qt Widgets Designer
1817 \nextpage Using a Designer UI File in Your Qt for Python Application
1818
1819 \keyword Using a Designer UI File in Your Application
1820 \title Using a Designer UI File in Your C++ Application
1821
1822 Qt Widgets Designer UI files represent the widget tree of the form in XML format. The
1823 forms can be processed:
1824
1825 \list
1826 \li \l{Compile Time Form Processing}{At compile time}, which means that forms
1827 are converted to C++ code that can be compiled.
1828 \li \l{Run Time Form Processing}{At runtime}, which means that forms are processed
1829 by the QUiLoader class that dynamically constructs the widget tree while
1830 parsing the XML file.
1831 \endlist
1832
1833 \section1 Compile Time Form Processing
1834
1835 You create user interface components with \QD and use Qt's integrated build tools,
1836 \l{qmake Manual}{qmake} and \l{User Interface Compiler (uic)}{uic}, to generate code
1837 for them when the application is built. The generated code contains the form's user
1838 interface object. It is a C++ struct that contains:
1839
1840 \list
1841 \li Pointers to the form's widgets, layouts, layout items,
1842 button groups, and actions.
1843 \li A member function called \c setupUi() to build the widget tree
1844 on the parent widget.
1845 \li A member function called \c retranslateUi() that handles the
1846 translation of the string properties of the form. For more information,
1847 see \l{Reacting to Language Changes}.
1848 \endlist
1849
1850 The generated code can be included in your application and used directly from
1851 it. Alternatively, you can use it to extend subclasses of standard widgets.
1852
1853 A compile time processed form can be used in your application with one of
1854 the following approaches:
1855
1856 \list
1857 \li \l{The Direct Approach}: you construct a widget to use as a placeholder
1858 for the component, and set up the user interface inside it.
1859 \li \l{The Single Inheritance Approach}: you subclass the form's base class
1860 (QWidget or QDialog, for example), and include a private instance
1861 of the form's user interface object.
1862 \li \l{The Multiple Inheritance Approach}: you subclass both the form's base
1863 class and the form's user interface object. This allows the widgets
1864 defined in the form to be used directly from within the scope of
1865 the subclass.
1866 \endlist
1867
1868 To demonstrate, we create a simple Calculator Form application. It is based on the
1869 original \l{Calculator Form} example.
1870
1871 The application consists of one source file, \c main.cpp and a UI
1872 file.
1873
1874 The \c{calculatorform.ui} file designed with \QD is shown below:
1875
1876 \image directapproach-calculatorform.png {Screenshot of form editor showing a
1877 calculator layout}
1878
1879 When using \c CMake to build the executable, a \c{CMakeLists.txt}
1880 file is required:
1881
1882 \snippet uitools/calculatorform/CMakeLists.txt 0
1883
1884 The form is listed among the C++ source files in \c qt_add_executable().
1885 The option \c CMAKE_AUTOUIC tells \c CMake to run the \c uic tool
1886 to create a \c ui_calculatorform.h file that can be used
1887 by the source files.
1888
1889 When using \c qmake to build the executable, a \c{.pro} file is required:
1890
1891 \snippet uitools/calculatorform/calculatorform.pro 0
1892
1893 The special feature of this file is the \c FORMS declaration that tells
1894 \c qmake which files to process with \c uic. In this case, the
1895 \c calculatorform.ui file is used to create a \c ui_calculatorform.h file
1896 that can be used by any file listed in the \c SOURCES declaration.
1897
1898 \note You can use Qt Creator to create the Calculator Form project. It
1899 automatically generates the main.cpp, UI, and a project file for the
1900 desired build tool, which you can modify.
1901
1902 \section2 The Direct Approach
1903
1904 To use the direct approach, we include the \c ui_calculatorform.h file
1905 directly in \c main.cpp:
1906
1907 \snippet uitools/calculatorform/main.cpp 0
1908
1909 The \c main function creates the calculator widget by constructing a
1910 standard QWidget that we use to host the user interface described by the
1911 \c calculatorform.ui file.
1912
1913 \snippet uitools/calculatorform/main.cpp 1
1914
1915 In this case, the \c{Ui::CalculatorForm} is an interface description object
1916 from the \c ui_calculatorform.h file that sets up all the dialog's widgets
1917 and the connections between its signals and slots.
1918
1919 The direct approach provides a quick and easy way to use simple, self-contained
1920 components in your applications. However, componens created with \QD often
1921 require close integration with the rest of the application code. For
1922 instance, the \c CalculatorForm code provided above will compile and run,
1923 but the QSpinBox objects will not interact with the QLabel as we need a
1924 custom slot to carry out the add operation and display the result in the
1925 QLabel. To achieve this, we need to use the single inheritance approach.
1926
1927 \section2 The Single Inheritance Approach
1928
1929 To use the single inheritance approach, we subclass a standard Qt widget and
1930 include a private instance of the form's user interface object. This can take
1931 the form of:
1932
1933 \list
1934 \li A member variable
1935 \li A pointer member variable
1936 \endlist
1937
1938 \section3 Using a Member Variable
1939
1940 In this approach, we subclass a Qt widget and set up the user interface
1941 from within the constructor. Components used in this way expose the widgets
1942 and layouts used in the form to the Qt widget subclass, and provide a
1943 standard system for making signal and slot connections between the user
1944 interface and other objects in your application.
1945 The generated \c{Ui::CalculatorForm} structure is a member of the class.
1946
1947 This approach is used in the \l{Calculator Form} example.
1948
1949 To ensure that we can use the user interface, we need to include the header
1950 file that \c uic generates before referring to \c{Ui::CalculatorForm}:
1951
1952 \snippet calculatorform/calculatorform.h 0
1953
1954 The project file must be updated to include \c{calculatorform.h}.
1955 For \c CMake:
1956
1957 \snippet calculatorform/CMakeLists.txt 1
1958
1959 In specific cases, such as the example below where the include directive
1960 uses a relative path, \l{qt6_add_ui}{qt_add_ui} can be used to generate the
1961 \c{ui_calculatorform.h} file instead of relying on
1962 \l{CMake AUTOUIC Documentation}{AUTOUIC}.
1963
1964 \l{When to prefer qt_add_ui over AUTOUIC}
1965
1966 \code
1967 #include "src/files/ui_calculatorform.h"
1968 \endcode
1969
1970 \code
1971 qt_add_ui(calculatorform SOURCES calculatorform.ui
1972 INCLUDE_PREFIX src/files)
1973 \endcode
1974
1975 For \c qmake:
1976
1977 \snippet calculatorform/calculatorform.pro 0
1978
1979 The subclass is defined in the following way:
1980
1981 \snippet calculatorform/calculatorform.h 1
1982
1983 The important feature of the class is the private \c ui object which
1984 provides the code for setting up and managing the user interface.
1985
1986 The constructor for the subclass constructs and configures all the widgets
1987 and layouts for the dialog just by calling the \c ui object's \c setupUi()
1988 function. Once this has been done, it is possible to modify the user
1989 interface as needed.
1990
1991 \snippet calculatorform/calculatorform.cpp 0
1992
1993 We can connect signals and slots in user interface widgets in the usual
1994 way by adding the on_<object name> - prefix. For more information,
1995 see \l{widgets-and-dialogs-with-auto-connect}.
1996
1997 The advantages of this approach are its simple use of inheritance to
1998 provide a QWidget-based interface, and its encapsulation of the user
1999 interface widget variables within the \c ui data member. We can use this
2000 method to define a number of user interfaces within the same widget, each
2001 of which is contained within its own namespace, and overlay (or compose)
2002 them. This approach can be used to create individual tabs from existing
2003 forms, for example.
2004
2005 \section3 Using a Pointer Member Variable
2006
2007 Alternatively, the \c{Ui::CalculatorForm} structure can be made a pointer
2008 member of the class. The header then looks as follows:
2009
2010 \code
2011
2012 namespace Ui {
2013 class CalculatorForm;
2014 }
2015
2016 class CalculatorForm : public QWidget
2017 ...
2018 virtual ~CalculatorForm();
2019 ...
2020 private:
2021 Ui::CalculatorForm *ui;
2022 ...
2023
2024 \endcode
2025
2026 The corresponding source file looks as follows:
2027
2028 \code
2029 #include "ui_calculatorform.h"
2030
2031 CalculatorForm::CalculatorForm(QWidget *parent) :
2032 QWidget(parent), ui(new Ui::CalculatorForm)
2033 {
2034 ui->setupUi(this);
2035 }
2036
2037 CalculatorForm::~CalculatorForm()
2038 {
2039 delete ui;
2040 }
2041 \endcode
2042
2043 The advantage of this approach is that the user interface object can be
2044 forward-declared, which means that we do not have to include the generated
2045 \c ui_calculatorform.h file in the header. The form can then be changed without
2046 recompiling the dependent source files. This is particularly important if the
2047 class is subject to binary compatibility restrictions.
2048
2049 We generally recommend this approach for libraries and large applications.
2050 For more information, see \l{Creating Shared Libraries}.
2051
2052 \section2 The Multiple Inheritance Approach
2053
2054 Forms created with \QD can be subclassed together with a standard
2055 QWidget-based class. This approach makes all the user interface components
2056 defined in the form directly accessible within the scope of the subclass,
2057 and enables signal and slot connections to be made in the usual way with
2058 the \l{QObject::connect()}{connect()} function.
2059
2060 We need to include the header file that \c uic generates from the
2061 \c calculatorform.ui file, as follows:
2062
2063 \snippet ../designer/calculatorform_mi/calculatorform.h 0
2064
2065 The class is defined in a similar way to the one used in the
2066 \l{The Single Inheritance Approach}{single inheritance approach}, except that
2067 this time we inherit from \e{both} QWidget and \c{Ui::CalculatorForm},
2068 as follows:
2069
2070 \snippet ../designer/calculatorform_mi/calculatorform.h 1
2071
2072 We inherit \c{Ui::CalculatorForm} privately to ensure that the user
2073 interface objects are private in our subclass. We can also inherit it with
2074 the \c public or \c protected keywords in the same way that we could have
2075 made \c ui public or protected in the previous case.
2076
2077 The constructor for the subclass performs many of the same tasks as the
2078 constructor used in the \l{The Single Inheritance Approach}
2079 {single inheritance} example:
2080
2081 \snippet ../designer/calculatorform_mi/calculatorform.cpp 0
2082
2083 In this case, the widgets used in the user interface can be accessed in the
2084 same say as a widget created in code by hand. We no longer require the
2085 \c{ui} prefix to access them.
2086
2087 \section2 Reacting to Language Changes
2088
2089 Qt notifies applications if the user interface language changes by sending an
2090 event of the type QEvent::LanguageChange. To call the member function
2091 \c retranslateUi() of the user interface object, we reimplement
2092 \c QWidget::changeEvent() in the form class, as follows:
2093
2094 \code
2095 void CalculatorForm::changeEvent(QEvent *e)
2096 {
2097 QWidget::changeEvent(e);
2098 switch (e->type()) {
2099 case QEvent::LanguageChange:
2100 ui->retranslateUi(this);
2101 break;
2102 default:
2103 break;
2104 }
2105 }
2106 \endcode
2107
2108 \section1 Run Time Form Processing
2109
2110 Alternatively, forms can be processed at run time, producing dynamically-
2111 generated user interfaces. This can be done using the QtUiTools module
2112 that provides the QUiLoader class to handle forms created with \QD.
2113
2114
2115 \section2 The UiTools Approach
2116
2117 A resource file containing a UI file is required to process forms at
2118 run time. Also, the application needs to be configured to use the QtUiTools
2119 module. This is done by including the following declarations in a \c CMake
2120 project file, ensuring that the application is compiled and linked
2121 appropriately.
2122
2123 \snippet ../uitools/textfinder/CMakeLists.txt 0
2124 \snippet ../uitools/textfinder/CMakeLists.txt 1
2125
2126 For \c qmake:
2127
2128 \snippet manual/doc_src_designer-manual.pro 0
2129
2130 The QUiLoader class provides a form loader object to construct the user
2131 interface. This user interface can be retrieved from any QIODevice, e.g.,
2132 a QFile object, to obtain a form stored in a project's resource file. The
2133 QUiLoader::load() function constructs the form widget using the user
2134 interface description contained in the file.
2135
2136 The QtUiTools module classes can be included using the following directive:
2137
2138 \snippet manual/doc_src_designer-manual.cpp 1
2139
2140 The QUiLoader::load() function is invoked as shown in this code from the
2141 \l{Text Finder} example:
2142
2143 \snippet ../uitools/textfinder/textfinder.cpp 4
2144
2145 In a class that uses QtUiTools to build its user interface at run time, we
2146 can locate objects in the form using QObject::findChild(). For example, in the
2147 following code, we locate some components based on their object names and
2148 widget types:
2149
2150 \snippet ../uitools/textfinder/textfinder.cpp 1
2151
2152 Processing forms at run-time gives the developer the freedom to change a
2153 program's user interface, just by changing the UI file. This is useful
2154 when customizing programs to suit various user needs, such as extra large
2155 icons or a different colour scheme for accessibility support.
2156
2157
2158 \section1 Automatic Connections
2159
2160 The signals and slots connections defined for compile time or run time
2161 forms can either be set up manually or automatically, using QMetaObject's
2162 ability to make connections between signals and suitably-named slots.
2163
2164 Generally, in a QDialog, if we want to process the information entered by
2165 the user before accepting it, we need to connect the clicked() signal from
2166 the \gui OK button to a custom slot in our dialog. We will first show an
2167 example of the dialog in which the slot is connected by hand then compare
2168 it with a dialog that uses automatic connection.
2169
2170
2171 \section2 A Dialog Without Auto-Connect
2172
2173 We define the dialog in the same way as before, but now include a slot in
2174 addition to the constructor:
2175
2176 \snippet noautoconnection/imagedialog.h 0
2177
2178 The \c checkValues() slot will be used to validate the values provided by
2179 the user.
2180
2181 In the dialog's constructor we set up the widgets as before, and connect
2182 the \gui Cancel button's \l{QPushButton::clicked()}{clicked()} signal to
2183 the dialog's reject() slot. We also disable the
2184 \l{QPushButton::autoDefault}{autoDefault} property in both buttons to
2185 ensure that the dialog does not interfere with the way that the line edit
2186 handles return key events:
2187
2188 \snippet noautoconnection/imagedialog.cpp 0
2189 \dots
2190 \snippet noautoconnection/imagedialog.cpp 1
2191
2192 We connect the \gui OK button's \l{QPushButton::clicked()}{clicked()}
2193 signal to the dialog's checkValues() slot which we implement as follows:
2194
2195 \snippet noautoconnection/imagedialog.cpp 2
2196
2197 This custom slot does the minimum necessary to ensure that the data
2198 entered by the user is valid - it only accepts the input if a name was
2199 given for the image.
2200
2201 \section2 Widgets and Dialogs with Auto-Connect
2202
2203 Although it is easy to implement a custom slot in the dialog and connect
2204 it in the constructor, we could instead use QMetaObject's auto-connection
2205 facilities to connect the \gui OK button's clicked() signal to a slot in
2206 our subclass. \c{uic} automatically generates code in the dialog's
2207 \c setupUi() function to do this, so we only need to declare and
2208 implement a slot with a name that follows a standard convention:
2209
2210 \snippet manual/doc_src_designer-manual.cpp 2
2211
2212 \note When renaming widgets in the form, the slot names need to be
2213 adapted accordingly, which can become a maintenance problem.
2214 For this reason, we recommend against using this in new code.
2215
2216 Using this convention, we can define and implement a slot that responds to
2217 mouse clicks on the \gui OK button:
2218
2219 \snippet autoconnection/imagedialog.h 0
2220
2221 Another example of automatic signal and slot connection would be the
2222 \l{Text Finder} with its \c{on_findButton_clicked()}
2223 slot.
2224
2225 We use QMetaObject's system to enable signal and slot connections:
2226
2227 \snippet ../uitools/textfinder/textfinder.cpp 2
2228
2229 This enables us to implement the slot, as shown below:
2230
2231 \snippet ../uitools/textfinder/textfinder.cpp 6
2232 \dots
2233 \snippet ../uitools/textfinder/textfinder.cpp 8
2234
2235 Automatic connection of signals and slots provides both a standard naming
2236 convention and an explicit interface for widget designers to work to. By
2237 providing source code that implements a given interface, user interface
2238 designers can check that their designs actually work without having to
2239 write code themselves.
2240*/
2241
2242/*!
2243 \page designer-using-a-ui-file-python.html
2244 \previouspage Using a Designer UI File in Your C++ Application
2245 \nextpage Using Custom Widgets with Qt Widgets Designer
2246
2247 \title Using a Designer UI File in Your Qt for Python Application
2248
2249 \section1 Converting the Form to Python Code
2250
2251 To demonstrate, we use the Qt Widgets animation easing example.
2252
2253 The application consists of one source file, \c easing.py, a UI
2254 file \c form.ui, a resource file \c easing.qrc and the project
2255 file, \c{easing.pyproject} file in the YAML format:
2256
2257 \code
2258 {
2259 "files": ["easing.qrc", "ui_form.py", "easing.py", "easing_rc.py",
2260 "form.ui"]
2261 }
2262 \endcode
2263
2264 The UI file is converted to Python code building the form using the
2265 \l{User Interface Compiler (uic)}:
2266
2267 \code
2268 uic -g python form.ui > ui_form.py
2269 \endcode
2270
2271 Since the top level widget is named \c Form, this results in a Python
2272 class named \c Ui_Form being generated. It provides a function
2273 \c setupUi(), taking the widget as parameter, which is called to
2274 create the UI elements:
2275
2276 \code
2277 from ui_form import Ui_Form
2278 ...
2279 class Window(QtWidgets.QWidget):
2280 def __init__(self, parent=None):
2281 super(Window, self).__init__(parent)
2282
2283 self.m_ui = Ui_Form()
2284 self.m_ui.setupUi(self)
2285 \endcode
2286
2287 Later on, the widgets can be accessed via the \c Ui_Form class:
2288
2289 \code
2290 self.m_ui.graphicsView.setScene(self.m_scene)
2291 \endcode
2292
2293 Besides \c setupUi(), \c Ui_Form provides another method
2294 \c retranslateUi(), which can be called in reaction to
2295 a QEvent of type QEvent.LanguageChange, which indicates
2296 a change in the application language.
2297
2298 \section2 The UiTools Approach
2299
2300 The QUiLoader class provides a form loader object to construct the user
2301 interface at runtime. This user interface can be retrieved from any
2302 QIODevice, e.g., a QFile object. The QUiLoader::load() function
2303 constructs the form widget using the user interface description
2304 contained in the file.
2305
2306 It is demonstrated by the uiloader example:
2307
2308 \code
2309 from PySide2.QtUiTools import QUiLoader
2310
2311 if __name__ == '__main__':
2312 # Some code to obtain the form file name, ui_file_name
2313 app = QApplication(sys.argv)
2314 ui_file = QFile(ui_file_name)
2315 if not ui_file.open(QIODevice.ReadOnly):
2316 print("Cannot open {}: {}".format(ui_file_name, ui_file.errorString()))
2317 sys.exit(-1)
2318 loader = QUiLoader()
2319 widget = loader.load(ui_file, None)
2320 ui_file.close()
2321 if not widget:
2322 print(loader.errorString())
2323 sys.exit(-1)
2324 widget.show()
2325 sys.exit(app.exec_())
2326 \endcode
2327
2328 \section1 Resource imports
2329
2330 \section2 Single directory usage
2331
2332 When using icons from \l{The Qt Resource System}{resource files}, say
2333 \c resources.qrc, \c uic will generate an import of the form:
2334
2335 \code
2336 import resources_rc
2337 \endcode
2338
2339 This assumes that a file \c resources_rc.py generated by calling the
2340 \l {Resource Compiler (rcc)} tool (passing the \c {-g python}
2341 command line option) exists in the same directory as the form source.
2342
2343 \c uic has a command line option \c --rc-prefix causing the \c rc indicator
2344 to be prepended:
2345
2346 \code
2347 import rc_resources
2348 \endcode
2349
2350 The command line option \c --from-imports causes the imports to be generated
2351 relative to '.':
2352
2353 \code
2354 from . import resources_rc
2355 \endcode
2356
2357 \section2 Directory trees
2358
2359 Some projects have more complicated directory trees, for example:
2360
2361 \badcode
2362 project
2363 resources (resources.qrc)
2364 ui (.ui files)
2365 \endcode
2366
2367 The resource file is then not in the same directory as the form source
2368 and the \c .ui files typically have relative paths to the resource files:
2369
2370 \badcode
2371 <include location="../resources/resources.qrc"/>
2372 \endcode
2373
2374 In this case, the command line option \c --absolute-imports can be used
2375 to generate an absolute import in Python, resulting in:
2376
2377 \code
2378 import resources.resources_rc
2379 \endcode
2380
2381 based on the assumption that \c .. is the root directory of the project
2382 contained in the Python import path list.
2383
2384 For more deeply nested trees, it is possible to use the
2385 command line option \c {--python-paths <path list>} to pass a Python
2386 import path list. \c uic will then try to determine the project root
2387 by matching the form file path against the path components.
2388
2389 If \c {--python-paths} is not given, the environment variable
2390 \c PYTHONPATH is by default checked.
2391*/
2392
2393/*!
2394 \page designer-customizing-forms.html
2395 \previouspage Using a Designer UI File in Your Qt for Python Application
2396 \nextpage Using Custom Widgets with Qt Widgets Designer
2397
2398 \title Customizing Qt Widgets Designer Forms
2399
2400 \image designer-form-settings.png {Screenshot of form settings window showing
2401 options to change author, edit layout default and function, include
2402 hints, and add pixmap function}
2403
2404 When saving a form in \QD, it is stored as a UI file. Several form
2405 settings, for example the grid settings or the margin and spacing for the
2406 default layout, are stored along with the form's components. These settings
2407 are used when the \l uic generates the form's C++ code. For more
2408 information on how to use forms in your application, see the
2409 \l{Using a Designer UI File in Your C++ Application} section.
2410
2411
2412 \section1 Modifying the Form Settings
2413
2414 To modify the form settings, open the \gui Form menu and select \gui{Form
2415 Settings...}
2416
2417 In the forms settings dialog you can specify the \gui Author of the form.
2418
2419 You can also alter the margin and spacing properties for the form's default
2420 layout (\gui {Layout Default}). These default layout properties will be
2421 replaced by the corresponding \gui {Layout Function}, if the function is
2422 specified, when \c uic generates code for the form. The form settings
2423 dialog lets you specify functions for both the margin and the spacing.
2424
2425 \target LayoutFunction
2426 \table
2427 \row
2428 \li \inlineimage designer-form-layoutfunction.png {Screenshot showing the
2429 option to enable or disable layout function and to edit
2430 margin and spacing of layout function}
2431 \li \b{Layout Function}
2432
2433 The default layout properties will be replaced by the corresponding
2434 \gui{Layout Function}, when \c uic generates code for the form. This is
2435 useful when different environments requires different layouts for the same
2436 form.
2437
2438 To specify layout functions for the form's margin and spacing, check the
2439 \gui{Layout Function} group box to enable the line edits.
2440 \endtable
2441
2442 You can also specify the form's \gui{Include Hints}; i.e., provide a list
2443 of the header files which will then be included in the form window's
2444 associated UI file. Header files may be local, i.e., relative to the
2445 project's directory, \c "mywidget.h", or global, i.e. part of Qt or the
2446 compilers standard libraries: \c <QtWidgets/QWidget>.
2447
2448 Finally, you can specify the function used to load pixmaps into the form
2449 window (the \gui {Pixmap Function}).
2450*/
2451
2452
2453/*!
2454 \page designer-using-custom-widgets.html
2455 \previouspage Customizing Qt Widgets Designer Forms
2456 \nextpage Creating Custom Widgets for Qt Widgets Designer
2457
2458 \title Using Custom Widgets with Qt Widgets Designer
2459
2460 \QD can display custom widgets through its extensible plugin mechanism,
2461 allowing the range of designable widgets to be extended by the user and
2462 third parties. Alternatively, it is possible
2463 to use existing widgets as placeholders for widget classes that provide
2464 similar APIs.
2465
2466
2467 \section1 Handling Custom Widgets
2468
2469 Although \QD supports all of the standard Qt widgets, some specialized
2470 widgets may not be available as standard for a number of reasons:
2471
2472 \list
2473 \li Custom widgets may not be available at the time the user interface
2474 is being designed.
2475 \li Custom widgets may be platform-specific, and designers may be
2476 developing the user interface on a different platform to end users.
2477 \li The source code for a custom widget is not available, or the user
2478 interface designers are unable to use the widget for non-technical
2479 reasons.
2480 \endlist
2481
2482 In the above situations, it is still possible to design forms with the aim
2483 of using custom widgets in the application. To achieve this, we can use
2484 the widget promotion feature of \QD.
2485
2486 In all other cases, where the source code to the custom widgets is
2487 available, we can adapt the custom widget for use with \QD.
2488
2489
2490 \section2 Promoting Widgets
2491
2492 \image designer-promoting-widgets.png {Screenshot of the Promoted Widgets window
2493 showing options to add a custom widget class by specifying a base class,
2494 promoted class name, and header file}
2495
2496 If some forms must be designed, but certain custom widgets are unavailble
2497 to the designer, we can substitute similar widgets to represent the missing
2498 widgets. For example, we might represent instances of a custom push button
2499 class, \c MyPushButton, with instances of QPushButton and promote these to
2500 \c MyPushButton so that \l{uic.html}{uic} generates suitable code for this
2501 missing class.
2502
2503 When choosing a widget to use as a placeholder, it is useful to compare the
2504 API of the missing widget with those of standard Qt widgets. For
2505 specialized widgets that subclass standard classes, the obvious choice of
2506 placeholder is the base class of the custom widget; for example, QSlider
2507 might be used for specialized QSlider subclasses.
2508
2509 For specialized widgets that do not share a common API with standard Qt
2510 widgets, it is worth considering adapting a custom widget for use in \QD.
2511 If this is not possible then QWidget is the obvious choice for a
2512 placeholder widget since it is the lowest common denominator for all
2513 widgets.
2514
2515 To add a placeholder, select an object of a suitable base class and choose
2516 \gui{Promote to ...} from the form's context menu. After entering the class
2517 name and header file in the lower part of the dialog, choose \gui{Add}. The
2518 placeholder class will now appear along with the base class in the upper
2519 list. Click the \gui{Promote} button to accept this choice.
2520
2521 Now, when the form's context menu is opened over objects of the base class,
2522 the placeholder class will appear in the \gui{Promote to} submenu, allowing
2523 for convenient promotion of objects to that class.
2524
2525 A promoted widget can be reverted to its base class by choosing
2526 \gui{Demote to} from the form's context menu.
2527
2528
2529 \section2 User Defined Custom Widgets
2530
2531 Custom widgets can be adapted for use with \QD, giving designers the
2532 opportunity to configure the user interface using the actual widgets that
2533 will be used in an application rather than placeholder widgets. The process
2534 of creating a custom widget plugin is described in the
2535 \l{Creating Custom Widgets for Qt Widgets Designer} chapter of this manual.
2536
2537 To use a plugin created in this way, it is necessary to ensure that the
2538 plugin is located on a path that \QD searches for plugins. Generally,
2539 plugins stored in \c{$QTDIR/plugins/designer} will be loaded when \QD
2540 starts. Further information on building and installing plugins can be found
2541 \l{Creating Custom Widgets for Qt Widgets Designer#BuildingandInstallingthePlugin}
2542 {here}. You can also refer to the \l{How to Create Qt Plugins}
2543 {Plugins HOWTO} document for information about creating plugins.
2544*/
2545
2546
2547/*!
2548 \page designer-creating-custom-widgets.html
2549 \previouspage Using Custom Widgets with Qt Widgets Designer
2550 \nextpage Creating Custom Widget Extensions
2551
2552 \title Creating Custom Widgets for Qt Widgets Designer
2553
2554 \QD's plugin-based architecture allows user-defined and third party custom
2555 widgets to be edited just like you do with standard Qt widgets. All of the
2556 custom widget's features are made available to \QD, including widget
2557 properties, signals, and slots. Since \QD uses real widgets during the form
2558 design process, custom widgets will appear the same as they do when
2559 previewed.
2560
2561 The \l QtDesigner module provides you with the ability to create custom
2562 widgets in \QD.
2563
2564
2565 \section1 Getting Started
2566
2567 To integrate a custom widget with \QD, you require a suitable description
2568 for the widget and an appropriate project file.
2569
2570
2571 \section2 Providing an Interface Description
2572
2573 To inform \QD about the type of widget you want to provide, create a
2574 subclass of QDesignerCustomWidgetInterface that describes the various
2575 properties your widget exposes. Most of these are supplied by functions
2576 that are pure virtual in the base class, because only the author of the
2577 plugin can provide this information.
2578
2579 \table
2580 \header
2581 \li Function
2582 \li Description of the return value
2583 \row
2584 \li \c name()
2585 \li The name of the class that provides the widget.
2586 \row
2587 \li \c group()
2588 \li The group in \QD's widget box that the widget belongs to.
2589 \row
2590 \li \c toolTip()
2591 \li A short description to help users identify the widget in \QD.
2592 \row
2593 \li \c whatsThis()
2594 \li A longer description of the widget for users of \QD.
2595 \row
2596 \li \c includeFile()
2597 \li The header file that must be included in applications that use
2598 this widget. This information is stored in UI files and will
2599 be used by \c uic to create a suitable \c{#includes} statement
2600 in the code it generates for the form containing the custom
2601 widget.
2602 \row
2603 \li \c icon()
2604 \li An icon that can be used to represent the widget in \QD's
2605 widget box.
2606 \row
2607 \li \c isContainer()
2608 \li True if the widget will be used to hold child widgets;
2609 false otherwise.
2610 \row
2611 \li \c createWidget()
2612 \li A QWidget pointer to an instance of the custom widget,
2613 constructed with the parent supplied.
2614 \note createWidget() is a factory function responsible for
2615 creating the widget only. The custom widget's properties will
2616 not be available until load() returns.
2617 \row
2618 \li \c domXml()
2619 \li A description of the widget's properties, such as its object
2620 name, size hint, and other standard QWidget properties.
2621 \row
2622 \li \c codeTemplate()
2623 \li This function is reserved for future use by \QD.
2624 \endtable
2625
2626 Two other virtual functions can also be reimplemented:
2627
2628 \table
2629 \row
2630 \li \c initialize()
2631 \li Sets up extensions and other features for custom widgets. Custom
2632 container extensions (see QDesignerContainerExtension) and task
2633 menu extensions (see QDesignerTaskMenuExtension) should be set
2634 up in this function.
2635 \row
2636 \li \c isInitialized()
2637 \li Returns true if the widget has been initialized; returns false
2638 otherwise. Reimplementations usually check whether the
2639 \c initialize() function has been called and return the result
2640 of this test.
2641 \endtable
2642
2643
2644 \section2 Notes on the \c{domXml()} Function
2645
2646 The \c{domXml()} function returns a UI file snippet that is used by
2647 \QD's widget factory to create a custom widget and its applicable
2648 properties.
2649
2650 Since Qt 4.4, \QD's widget box allows for a complete UI file to
2651 describe \b one custom widget. The UI file can be loaded using the
2652 \c{<ui>} tag. Specifying the <ui> tag allows for adding the <customwidget>
2653 element that contains additional information for custom widgets. The
2654 \c{<widget>} tag is sufficient if no additional information is required
2655
2656 If the custom widget does not provide a reasonable size hint, it is
2657 necessary to specify a default geometry in the string returned by the
2658 \c domXml() function in your subclass. For example, the
2659 \c AnalogClockPlugin provided by the \l{customwidgetplugin}
2660 {Custom Widget Plugin} example, defines a default widgetgeometry in the
2661 following way:
2662
2663 \dots
2664 \snippet customwidgetplugin/customwidgetplugin.cpp 11
2665 \dots
2666
2667 An additional feature of the \c domXml() function is that, if it returns
2668 an empty string, the widget will not be installed in \QD's widget box.
2669 However, it can still be used by other widgets in the form. This feature
2670 is used to hide widgets that should not be explicitly created by the user,
2671 but are required by other widgets.
2672
2673 A complete custom widget specification looks like:
2674
2675 \code
2676<ui language="c++"> displayname="MyWidget">
2677 <widget class="widgets::MyWidget" name="mywidget"/>
2678 <customwidgets>
2679 <customwidget>
2680 <class>widgets::MyWidget</class>
2681 <addpagemethod>addPage</addpagemethod>
2682 <propertyspecifications>
2683 <stringpropertyspecification name="fileName" notr="true" type="singleline"/>
2684 <stringpropertyspecification name="text" type="richtext"/>
2685 <tooltip name="text">Explanatory text to be shown in Property Editor</tooltip>
2686 </propertyspecifications>
2687 </customwidget>
2688 </customwidgets>
2689</ui>
2690 \endcode
2691
2692 Attributes of the \c{<ui>} tag:
2693 \table
2694 \header
2695 \li Attribute
2696 \li Presence
2697 \li Values
2698 \li Comment
2699 \row
2700 \li \c{language}
2701 \li optional
2702 \li "c++", "jambi"
2703 \li This attribute specifies the language the custom widget is intended for.
2704 It is mainly there to prevent C++-plugins from appearing in Qt Jambi.
2705 \row
2706 \li \c{displayname}
2707 \li optional
2708 \li Class name
2709 \li The value of the attribute appears in the Widget box and can be used to
2710 strip away namespaces.
2711 \endtable
2712
2713 The \c{<addpagemethod>} tag tells \QD and \l uic which method should be used to
2714 add pages to a container widget. This applies to container widgets that require
2715 calling a particular method to add a child rather than adding the child by passing
2716 the parent. In particular, this is relevant for containers that are not a
2717 a subclass of the containers provided in \QD, but are based on the notion
2718 of \e{Current Page}. In addition, you need to provide a container extension
2719 for them.
2720
2721 The \c{<propertyspecifications>} element can contain a list of property meta information.
2722
2723 The tag \c{<tooltip>} may be used to specify a tool tip to be shown in Property Editor
2724 when hovering over the property. The property name is given in the attribute \c name and
2725 the element text is the tooltip. This functionality was added in Qt 5.6.
2726
2727 For properties of type string, the \c{<stringpropertyspecification>} tag can be used.
2728 This tag has the following attributes:
2729
2730 \table
2731 \header
2732 \li Attribute
2733 \li Presence
2734 \li Values
2735 \li Comment
2736 \row
2737 \li \c{name}
2738 \li required
2739 \li Name of the property
2740 \row
2741 \li \c{type}
2742 \li required
2743 \li See below table
2744 \li The value of the attribute determines how the property editor will handle them.
2745 \row
2746 \li \c{notr}
2747 \li optional
2748 \li "true", "false"
2749 \li If the attribute is "true", the value is not meant to be translated.
2750 \endtable
2751
2752 Values of the \c{type} attribute of the string property:
2753
2754 \table
2755 \header
2756 \li Value
2757 \li Type
2758 \row
2759 \li \c{"richtext"}
2760 \li Rich text.
2761 \row
2762 \li \c{"multiline"}
2763 \li Multi-line plain text.
2764 \row
2765 \li \c{"singleline"}
2766 \li Single-line plain text.
2767 \row
2768 \li \c{"stylesheet"}
2769 \li A CSS-style sheet.
2770 \row
2771 \li \c{"objectname"}
2772 \li An object name (restricted set of valid characters).
2773 \row
2774 \li \c{"url"}
2775 \li URL, file name.
2776 \endtable
2777
2778 \section1 Plugin Requirements
2779
2780 In order for plugins to work correctly on all platforms, you need to ensure
2781 that they export the symbols needed by \QD.
2782
2783 First of all, the plugin class must be exported in order for the plugin to
2784 be loaded by \QD. Use the Q_PLUGIN_METADATA() macro to do this. Also, the
2785 QDESIGNER_WIDGET_EXPORT macro must be used to define each custom widget class
2786 within a plugin, that \QD will instantiate.
2787
2788
2789 \section1 Creating Well Behaved Widgets
2790
2791 Some custom widgets have special user interface features that may make them
2792 behave differently to many of the standard widgets found in \QD.
2793 Specifically, if a custom widget grabs the keyboard as a result of a call
2794 to QWidget::grabKeyboard(), the operation of \QD will be affected.
2795
2796 To give custom widgets special behavior in \QD, provide an implementation
2797 of the initialize() function to configure the widget construction process
2798 for \QD specific behavior. This function will be called for the first time
2799 before any calls to createWidget() and could perhaps set an internal flag
2800 that can be tested later when \QD calls the plugin's createWidget()
2801 function.
2802
2803
2804 \target BuildingandInstallingthePlugin
2805 \section1 Building and Installing the Plugin
2806
2807 \section2 A Simple Plugin
2808
2809 The \l{Custom Widget Plugin} demonstrates a simple \QD plugin.
2810
2811 The project file for a plugin must specify the headers and sources for
2812 both the custom widget and the plugin interface. Typically, this file only
2813 has to specify that the plugin's project will be built as a library, but
2814 with specific plugin support for \QD. For \c CMake, this is done with
2815 the following declarations:
2816
2817 \snippet customwidgetplugin/CMakeLists.txt 0
2818 \snippet customwidgetplugin/CMakeLists.txt 1
2819 \snippet customwidgetplugin/CMakeLists.txt 2
2820
2821 The link libraries list specifies \c Qt::UiPlugin. This indicates that
2822 the plugin uses the abstract interfaces QDesignerCustomWidgetInterface
2823 and QDesignerCustomWidgetCollectionInterface only and has no linkage
2824 to the \QD libraries. When accessing other interfaces of \QD that have
2825 linkage, \c Designer should be used instead; this ensures that the plugin
2826 dynamically links to the \QD libraries and has a run-time dependency on
2827 them.
2828
2829 It is also necessary to ensure that the plugin is installed together with
2830 other \QD widget plugins:
2831
2832 \snippet customwidgetplugin/CMakeLists.txt 3
2833 \snippet customwidgetplugin/CMakeLists.txt 4
2834
2835 For \c qmake:
2836
2837 \snippet customwidgetplugin/customwidgetplugin.pro 0
2838 \snippet customwidgetplugin/customwidgetplugin.pro 2
2839
2840 The \c QT variable contains the keyword \c uiplugin, which is
2841 the equivalent of the \c Qt::UiPlugin library.
2842
2843 It is also necessary to ensure that the plugin is installed together with
2844 other \QD widget plugins:
2845
2846 \snippet manual/doc_src_designer-manual.pro 4
2847
2848 The \c $[QT_INSTALL_PLUGINS] variable is a placeholder to the location of
2849 the installed Qt plugins. You can configure \QD to look for plugins in
2850 other locations by setting the \c QT_PLUGIN_PATH environment variable
2851 before running the application.
2852
2853 \note \QD will look for a \c designer subdirectory in each path supplied.
2854
2855 See QCoreApplication::libraryPaths() for more information about customizing
2856 paths for libraries and plugins with Qt applications.
2857
2858 If plugins are built in a mode that is incompatible with \QD, they will
2859 not be loaded and installed. For more information about plugins, see the
2860 \l{plugins-howto.html}{Plugins HOWTO} document.
2861
2862 \section2 Splitting up the Plugin
2863
2864 The simple approach explained above introduces a problem particularly
2865 when using the other interfaces of \QD that have linkage:
2866 The application using the custom widget will then depend on
2867 \QD headers and libraries. In a real world scenario, this is not desired.
2868
2869 The following sections describe how to resolve this.
2870
2871 \section3 Linking the Widget into the Application
2872
2873 When using \c qmake, the source and header file of the custom widget
2874 can be shared between the application and \QD by creating a \c{.pri}
2875 file for inclusion:
2876
2877 \code
2878 INCLUDEPATH += $$PWD
2879 HEADERS += $$PWD/analogclock.h
2880 SOURCES += $$PWD/analogclock.cpp
2881 \endcode
2882
2883 This file would then be included by the \c{.pro} file of the plugin and
2884 the application:
2885
2886 \code
2887 include(customwidget.pri)
2888 \endcode
2889
2890 When using \c CMake, the source files of the widget can similarly be
2891 added to the application project.
2892
2893 \section3 Sharing the Widget Using a Library
2894
2895 Another approach is to put the widget into a library that is linked to
2896 the \QD plugin as well as to the application. It is recommended to
2897 use static libraries to avoid problems locating the library at run-time.
2898
2899 For shared libraries, see \l{sharedlibrary.html}{Creating Shared Libraries}.
2900
2901 \section3 Using the Plugin with QUiLoader
2902
2903 The preferred way of adding custom widgets to QUiLoader is to subclass it
2904 reimplementing QUiLoader::createWidget().
2905
2906 However, it is also possible to use \QD custom widget plugins
2907 (see QUiLoader::pluginPaths() and related functions). To avoid having
2908 to deploy the \QD libraries onto the target device, those plugins should
2909 have no linkage to the \QD libraries (\c {QT = uiplugin}, see
2910 \l{Creating Custom Widgets for Qt Widgets Designer#BuildingandInstallingthePlugin}).
2911
2912 \section1 Related Examples
2913
2914 For more information on using custom widgets in \QD, refer to the
2915 \l{customwidgetplugin}{Custom Widget Plugin} and
2916 \l{taskmenuextension}{Task Menu Extension} examples for more
2917 information about using custom widgets in \QD. Also, you can use the
2918 QDesignerCustomWidgetCollectionInterface class to combine several custom
2919 widgets into a single library.
2920*/
2921
2922
2923/*!
2924 \page designer-creating-custom-widgets-extensions.html
2925 \previouspage Creating Custom Widgets for Qt Widgets Designer
2926 \nextpage Qt Widgets Designer's UI File Format
2927
2928 \title Creating Custom Widget Extensions
2929
2930 Once you have a custom widget plugin for \QD, you can provide it with the
2931 expected behavior and functionality within \QD's workspace, using custom
2932 widget extensions.
2933
2934
2935 \section1 Extension Types
2936
2937 There are several available types of extensions in \QD. You can use all of
2938 these extensions in the same pattern, only replacing the respective
2939 extension base class.
2940
2941 QDesignerContainerExtension is necessary when implementing a custom
2942 multi-page container.
2943
2944 \table
2945 \row
2946 \li \inlineimage designer-manual-taskmenuextension.png {Screenshot
2947 of designer editor canvas showing a simple custom
2948 widget with a context menu open, highlighting the
2949 “Edit State" option}
2950 \li \b{QDesignerTaskMenuExtension}
2951
2952 QDesignerTaskMenuExtension is useful for custom widgets. It provides an
2953 extension that allows you to add custom menu entries to \QD's task
2954 menu.
2955
2956 The \l{taskmenuextension}{Task Menu Extension} example
2957 illustrates how to use this class.
2958
2959 \row
2960 \li \inlineimage designer-manual-containerextension.png {Screenshot
2961 of designer editor showing a container and an open
2962 context menu}
2963 \li \b{QDesignerContainerExtension}
2964
2965 QDesignerContainerExtension is necessary when implementing a custom
2966 multi-page container. It provides an extension that allows you to add
2967 and delete pages for a multi-page container plugin in \QD.
2968
2969 The \l{containerextension}{Container Extension} example
2970 further explains how to use this class.
2971
2972 \note It is not possible to add custom per-page properties for some
2973 widgets (e.g., QTabWidget) due to the way they are implemented.
2974 \endtable
2975
2976 \table
2977 \row
2978 \li \inlineimage designer-manual-membersheetextension.png {Screenshot
2979 of "Configure Connecttion" showing which functions
2980 should the connected widgets send to each other}
2981 \li \b{QDesignerMemberSheetExtension}
2982
2983 The QDesignerMemberSheetExtension class allows you to manipulate a
2984 widget's member functions displayed when connecting signals and slots.
2985
2986 \row
2987 \li \inlineimage designer-manual-propertysheetextension.png {Screenshot
2988 of "Property Editor" showing the properties, and
2989 settings used for an object}
2990 \li \b{QDesignerPropertySheetExtension,
2991 QDesignerDynamicPropertySheetExtension}
2992
2993 These extension classes allow you to control how a widget's properties
2994 are displayed in \QD's property editor.
2995 \endtable
2996
2997\omit
2998 \row
2999 \li
3000 \li \b {QDesignerScriptExtension}
3001
3002 The QDesignerScriptExtension class allows you to define script
3003 snippets that are executed when a form is loaded. The extension
3004 is primarily intended to be used to set up the internal states
3005 of custom widgets.
3006 \endtable
3007\endomit
3008
3009
3010 \QD uses the QDesignerPropertySheetExtension and the
3011 QDesignerMemberSheetExtension classes to feed its property and signal and
3012 slot editors. Whenever a widget is selected in its workspace, \QD will
3013 query for the widget's property sheet extension; likewise, whenever a
3014 connection between two widgets is requested, \QD will query for the
3015 widgets' member sheet extensions.
3016
3017 \warning All widgets have default property and member sheets. If you
3018 implement custom property sheet or member sheet extensions, your custom
3019 extensions will override the default sheets.
3020
3021
3022 \section1 Creating an Extension
3023
3024 To create an extension you must inherit both QObject and the appropriate
3025 base class, and reimplement its functions. Since we are implementing an
3026 interface, we must ensure that it is made known to the meta object system
3027 using the Q_INTERFACES() macro in the extension class's definition. For
3028 example:
3029
3030 \snippet manual/doc_src_designer-manual.cpp 7
3031
3032 This enables \QD to use the qobject_cast() function to query for supported
3033 interfaces using a QObject pointer only.
3034
3035
3036 \section1 Exposing an Extension to Qt Widgets Designer
3037
3038 In \QD the extensions are not created until they are required. For this
3039 reason, when implementing extensions, you must subclass QExtensionFactory
3040 to create a class that is able to make instances of your extensions. Also,
3041 you must register your factory with \QD's extension manager; the extension
3042 manager handles the construction of extensions.
3043
3044 When an extension is requested, \QD's extension manager will run through
3045 its registered factories calling QExtensionFactory::createExtension() for
3046 each of them until it finds one that is able to create the requested
3047 extension for the selected widget. This factory will then make an instance
3048 of the extension.
3049
3050 \image qtdesignerextensions.png {Diagram showing relation between
3051 \QD components}
3052
3053
3054 \section2 Creating an Extension Factory
3055
3056 The QExtensionFactory class provides a standard extension factory, but it
3057 can also be used as an interface for custom extension factories.
3058
3059 The purpose is to reimplement the QExtensionFactory::createExtension()
3060 function, making it able to create your extension, such as a
3061 \l{containerextension}{MultiPageWidget} container extension.
3062
3063 You can either create a new QExtensionFactory and reimplement the
3064 QExtensionFactory::createExtension() function:
3065
3066 \snippet manual/doc_src_designer-manual.cpp 8
3067
3068 or you can use an existing factory, expanding the
3069 QExtensionFactory::createExtension() function to enable the factory to
3070 create your custom extension as well:
3071
3072 \snippet manual/doc_src_designer-manual.cpp 9
3073
3074
3075 \section2 Accessing Qt Widgets Designer's Extension Manager
3076
3077 When implementing a custom widget plugin, you must subclass the
3078 QDesignerCustomWidgetInterface to expose your plugin to \QD. This is
3079 covered in more detail in the
3080 \l{Creating Custom Widgets for Qt Widgets Designer} section. The registration of
3081 an extension factory is typically made in the
3082 QDesignerCustomWidgetInterface::initialize() function:
3083
3084 \snippet manual/doc_src_designer-manual.cpp 10
3085
3086 The \c formEditor parameter in the
3087 QDesignerCustomWidgetInterface::initialize() function is a pointer to \QD's
3088 current QDesignerFormEditorInterface object. You must use the
3089 QDesignerFormEditorInterface::extensionManager() function to retrieve an
3090 interface to \QD's extension manager. Then you use the
3091 QExtensionManager::registerExtensions() function to register your custom
3092 extension factory.
3093
3094
3095 \section1 Related Examples
3096
3097 For more information on creating custom widget extensions in \QD, refer to
3098 the \l{taskmenuextension}{Task Menu Extension} and
3099 \l{containerextension}{Container Extension} examples.
3100*/
3101
3102
3103/*!
3104 \page designer-ui-file-format.html
3105 \previouspage Creating Custom Widget Extensions
3106
3107 \title Qt Widgets Designer's UI File Format
3108
3109 The \c UI file format used by \QD is described by the
3110 \l{http://www.w3.org/XML/Schema}{XML schema} presented below,
3111 which we include for your convenience. Be aware that the format
3112 may change in future Qt releases.
3113
3114 \quotefile ../../../../data/ui4.xsd
3115*/