}
/*!
- Returns the color that the user selected by clicking the \gui{OK}
+ Returns the color that the user selected by clicking the \uicontrol{OK}
or equivalent button.
\note This color is not always the same as the color held by the
of a color dialog.
\value ShowAlphaChannel Allow the user to select the alpha component of a color.
- \value NoButtons Don't display \gui{OK} and \gui{Cancel} buttons. (Useful for "live dialogs".)
+ \value NoButtons Don't display \uicontrol{OK} and \uicontrol{Cancel} buttons. (Useful for "live dialogs".)
\value DontUseNativeDialog Use Qt's standard color dialog on the Mac instead of Apple's
native color panel.
/*!
\fn void QColorDialog::colorSelected(const QColor &color);
- This signal is emitted just after the user has clicked \gui{OK} to
+ This signal is emitted just after the user has clicked \uicontrol{OK} to
select a color to use. The chosen color is specified by \a color.
\sa color, currentColorChanged()
initially set to \a initial. The dialog is a child of \a parent.
If \a ok is non-null, \e *\a ok is set to true if the user clicked
- \gui{OK}, and to false if the user clicked Cancel.
+ \uicontrol{OK}, and to false if the user clicked Cancel.
If the user clicks Cancel, the \a initial value is returned.
exec() function. When the user closes the dialog, exec() will
provide a useful \link #return return value\endlink. Typically,
to get the dialog to close and return the appropriate value, we
- connect a default button, e.g. \gui OK, to the accept() slot and a
- \gui Cancel button to the reject() slot.
+ connect a default button, e.g. \uicontrol OK, to the accept() slot and a
+ \uicontrol Cancel button to the reject() slot.
Alternatively you can call the done() slot with \c Accepted or
\c Rejected.
partial dialog that shows the most commonly used options, and a
full dialog that shows all the options. Typically an extensible
dialog will initially appear as a partial dialog, but with a
- \gui More toggle button. If the user presses the \gui More button down,
+ \uicontrol More toggle button. If the user presses the \uicontrol More button down,
the dialog is expanded. The \l{Extension Example} shows how to achieve
extensible dialogs using Qt.
\section1 Return Value (Modal Dialogs)
Modal dialogs are often used in situations where a return value is
- required, e.g. to indicate whether the user pressed \gui OK or
- \gui Cancel. A dialog can be closed by calling the accept() or the
+ required, e.g. to indicate whether the user pressed \uicontrol OK or
+ \uicontrol Cancel. A dialog can be closed by calling the accept() or the
reject() slots, and exec() will return \c Accepted or \c Rejected
as appropriate. The exec() call returns the result of the dialog.
The result is also available from result() if the dialog has not
A modal dialog:
- \snippet doc/src/snippets/dialogs/dialogs.cpp 1
+ \snippet dialogs/dialogs.cpp 1
A modeless dialog:
- \snippet doc/src/snippets/dialogs/dialogs.cpp 0
+ \snippet dialogs/dialogs.cpp 0
\sa QDialogButtonBox, QTabWidget, QWidget, QProgressDialog,
{fowler}{GUI Design Handbook: Dialogs, Standard}, {Extension Example},
functions. On Windows, Mac OS X, KDE and GNOME, these static functions will
call the native file dialog when possible.
- \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 0
+ \snippet code/src_gui_dialogs_qfiledialog.cpp 0
In the above example, a modal QFileDialog is created using a static
function. The dialog initially displays the contents of the "/home/jana"
If you want to use multiple filters, separate each one with
\e two semicolons. For example:
- \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 1
+ \snippet code/src_gui_dialogs_qfiledialog.cpp 1
You can create your own QFileDialog without using the static
functions. By calling setFileMode(), you can specify what the user must
select in the dialog:
- \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 2
+ \snippet code/src_gui_dialogs_qfiledialog.cpp 2
In the above example, the mode of the file dialog is set to
AnyFile, meaning that the user can select any file, or even specify a
this indicates what types of objects the user is expected to select.
Use setNameFilter() to set the dialog's file filter. For example:
- \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 3
+ \snippet code/src_gui_dialogs_qfiledialog.cpp 3
In the above example, the filter is set to \c{"Images (*.png *.xpm *.jpg)"},
this means that only files with the extension \c png, \c xpm,
information alongside each name, such as the file size and modification
date. Set the mode with setViewMode():
- \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 4
+ \snippet code/src_gui_dialogs_qfiledialog.cpp 4
The last important function you will need to use when creating your
own file dialog is selectedFiles().
- \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 5
+ \snippet code/src_gui_dialogs_qfiledialog.cpp 5
In the above example, a modal file dialog is created and shown. If
the user clicked OK, the file they selected is put in \c fileName.
For instance:
- \snippet doc/src/snippets/filedialogurls.cpp 0
+ \snippet filedialogurls.cpp 0
The file dialog will then look like this:
text contained in the parentheses is used as the filter. This means
that these calls are all equivalent:
- \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 6
+ \snippet code/src_gui_dialogs_qfiledialog.cpp 6
\sa setNameFilters()
*/
Sets the \a filters used in the file dialog.
- \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 7
+ \snippet code/src_gui_dialogs_qfiledialog.cpp 7
*/
void QFileDialog::setNameFilters(const QStringList &filters)
{
This is a convenience static function that returns an existing file
selected by the user. If the user presses Cancel, it returns a null string.
- \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 8
+ \snippet code/src_gui_dialogs_qfiledialog.cpp 8
The function creates a modal file dialog with the given \a parent widget.
If \a parent is not 0, the dialog will be shown centered over the parent
This is a convenience static function that will return one or more existing
files selected by the user.
- \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 9
+ \snippet code/src_gui_dialogs_qfiledialog.cpp 9
This function creates a modal file dialog with the given \a parent widget.
If \a parent is not 0, the dialog will be shown centered over the parent
\note If you want to iterate over the list of files, you should iterate
over a copy. For example:
- \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 10
+ \snippet code/src_gui_dialogs_qfiledialog.cpp 10
\warning Do not delete \a parent during the execution of the dialog. If you
want to do this, you should create the dialog yourself using one of the
\a parent is not 0, the dialog will be shown centered over the parent
widget.
- \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 11
+ \snippet code/src_gui_dialogs_qfiledialog.cpp 11
The file dialog's working directory will be set to \a dir. If \a dir
includes a file name, the file will be selected. Only files that match the
This is a convenience static function that will return an existing
directory selected by the user.
- \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 12
+ \snippet code/src_gui_dialogs_qfiledialog.cpp 12
This function creates a modal file dialog with the given \a parent widget.
If \a parent is not 0, the dialog will be shown centered over the parent
A directory model that displays the contents of a default directory
is usually constructed with a parent object:
- \snippet doc/src/snippets/shareddirmodel/main.cpp 2
+ \snippet shareddirmodel/main.cpp 2
A tree view can be used to display the contents of the model
- \snippet doc/src/snippets/shareddirmodel/main.cpp 4
+ \snippet shareddirmodel/main.cpp 4
and the contents of a particular directory can be displayed by
setting the tree view's root index:
- \snippet doc/src/snippets/shareddirmodel/main.cpp 7
+ \snippet shareddirmodel/main.cpp 7
The view's root index can be used to control how much of a
hierarchical model is displayed. QDirModel provides a convenience
Examples:
- \snippet doc/src/snippets/code/src_gui_dialogs_qfontdialog.cpp 0
+ \snippet code/src_gui_dialogs_qfontdialog.cpp 0
The dialog can also be used to set a widget's font directly:
- \snippet doc/src/snippets/code/src_gui_dialogs_qfontdialog.cpp 1
+ \snippet code/src_gui_dialogs_qfontdialog.cpp 1
If the user clicks OK the font they chose will be used for myWidget,
and if they click Cancel the original font is used.
/*!
Executes a modal font dialog and returns a font.
- If the user clicks \gui OK, the selected font is returned. If the user
- clicks \gui Cancel, the \a initial font is returned.
+ If the user clicks \uicontrol OK, the selected font is returned. If the user
+ clicks \uicontrol Cancel, the \a initial font is returned.
The dialog is constructed with the given \a parent and the options specified
in \a options. \a title is shown as the window title of the dialog and \a
initial is the initially selected font. If the \a ok parameter is not-null,
- the value it refers to is set to true if the user clicks \gui OK, and set to
- false if the user clicks \gui Cancel.
+ the value it refers to is set to true if the user clicks \uicontrol OK, and set to
+ false if the user clicks \uicontrol Cancel.
Examples:
- \snippet doc/src/snippets/code/src_gui_dialogs_qfontdialog.cpp 2
+ \snippet code/src_gui_dialogs_qfontdialog.cpp 2
The dialog can also be used to set a widget's font directly:
- \snippet doc/src/snippets/code/src_gui_dialogs_qfontdialog.cpp 3
+ \snippet code/src_gui_dialogs_qfontdialog.cpp 3
In this example, if the user clicks OK the font they chose will be
used, and if they click Cancel the original font is used.
Executes a modal font dialog and returns a font.
- If the user clicks \gui OK, the selected font is returned. If the user
- clicks \gui Cancel, the Qt default font is returned.
+ If the user clicks \uicontrol OK, the selected font is returned. If the user
+ clicks \uicontrol Cancel, the Qt default font is returned.
The dialog is constructed with the given \a parent.
If the \a ok parameter is not-null, the value it refers to is set
- to true if the user clicks \gui OK, and false if the user clicks
- \gui Cancel.
+ to true if the user clicks \uicontrol OK, and false if the user clicks
+ \uicontrol Cancel.
Example:
- \snippet doc/src/snippets/code/src_gui_dialogs_qfontdialog.cpp 4
+ \snippet code/src_gui_dialogs_qfontdialog.cpp 4
\warning Do not delete \a parent during the execution of the dialog.
If you want to do this, you should create the dialog
}
/*!
- Returns the font that the user selected by clicking the \gui{OK}
+ Returns the font that the user selected by clicking the \uicontrol{OK}
or equivalent button.
\note This font is not always the same as the font held by the
This enum specifies various options that affect the look and feel
of a font dialog.
- \value NoButtons Don't display \gui{OK} and \gui{Cancel} buttons. (Useful for "live dialogs".)
+ \value NoButtons Don't display \uicontrol{OK} and \uicontrol{Cancel} buttons. (Useful for "live dialogs".)
\value DontUseNativeDialog Use Qt's standard font dialog on the Mac instead of Apple's
native font panel. (Currently, the native dialog is never used,
but this is likely to change in future Qt releases.)
getDouble(), and getItem(). All the functions can be used in a similar way,
for example:
- \snippet examples/dialogs/standarddialogs/dialog.cpp 3
+ \snippet dialogs/standarddialogs/dialog.cpp 3
- The \c ok variable is set to true if the user clicks \gui OK; otherwise it
+ The \c ok variable is set to true if the user clicks \uicontrol OK; otherwise it
is set to false.
\img inputdialogs.png Input Dialogs
This enum specifies various options that affect the look and feel
of an input dialog.
- \value NoButtons Don't display \gui{OK} and \gui{Cancel} buttons. (Useful for "live dialogs".)
+ \value NoButtons Don't display \uicontrol{OK} and \uicontrol{Cancel} buttons. (Useful for "live dialogs".)
\value UseListViewForComboBoxItems Use a QListView rather than a non-editable QComboBox for
displaying the items set with setComboBoxItems().
edit widget if an input method is active.
If \a ok is nonnull \e *\a ok will be set to true if the user pressed
- \gui OK and to false if the user pressed \gui Cancel. The dialog's parent
+ \uicontrol OK and to false if the user pressed \uicontrol Cancel. The dialog's parent
is \a parent. The dialog will be modal and uses the specified widget
\a flags.
Use this static function like this:
- \snippet examples/dialogs/standarddialogs/dialog.cpp 3
+ \snippet dialogs/standarddialogs/dialog.cpp 3
\warning Do not delete \a parent during the execution of the dialog. If you
want to do this, you should create the dialog yourself using one of the
\a step is the amount by which the values change as the user presses the
arrow buttons to increment or decrement the value.
- If \a ok is nonnull *\a ok will be set to true if the user pressed \gui OK
- and to false if the user pressed \gui Cancel. The dialog's parent is
+ If \a ok is nonnull *\a ok will be set to true if the user pressed \uicontrol OK
+ and to false if the user pressed \uicontrol Cancel. The dialog's parent is
\a parent. The dialog will be modal and uses the widget \a flags.
On success, this function returns the integer which has been entered by the
Use this static function like this:
- \snippet examples/dialogs/standarddialogs/dialog.cpp 0
+ \snippet dialogs/standarddialogs/dialog.cpp 0
\warning Do not delete \a parent during the execution of the dialog. If you
want to do this, you should create the dialog yourself using one of the
\a min and \a max are the minimum and maximum values the user may choose.
\a decimals is the maximum number of decimal places the number may have.
- If \a ok is nonnull, *\a ok will be set to true if the user pressed \gui OK
- and to false if the user pressed \gui Cancel. The dialog's parent is
+ If \a ok is nonnull, *\a ok will be set to true if the user pressed \uicontrol OK
+ and to false if the user pressed \uicontrol Cancel. The dialog's parent is
\a parent. The dialog will be modal and uses the widget \a flags.
This function returns the floating point number which has been entered by
Use this static function like this:
- \snippet examples/dialogs/standarddialogs/dialog.cpp 1
+ \snippet dialogs/standarddialogs/dialog.cpp 1
\warning Do not delete \a parent during the execution of the dialog. If you
want to do this, you should create the dialog yourself using one of the
user may only select one of the existing items.
If \a ok is nonnull \e *\a ok will be set to true if the user pressed
- \gui OK and to false if the user pressed \gui Cancel. The dialog's parent
+ \uicontrol OK and to false if the user pressed \uicontrol Cancel. The dialog's parent
is \a parent. The dialog will be modal and uses the widget \a flags.
This function returns the text of the current item, or if \a editable is
Use this static function like this:
- \snippet examples/dialogs/standarddialogs/dialog.cpp 2
+ \snippet dialogs/standarddialogs/dialog.cpp 2
\warning Do not delete \a parent during the execution of the dialog. If you
want to do this, you should create the dialog yourself using one of the
\fn void QInputDialog::doubleValueSelected(double value)
This signal is emitted whenever the user selects a double value by
- accepting the dialog; for example, by clicking the \gui{OK} button.
+ accepting the dialog; for example, by clicking the \uicontrol{OK} button.
The selected value is specified by \a value.
This signal is only relevant when the input dialog is used in
\fn void QInputDialog::intValueSelected(int value)
This signal is emitted whenever the user selects a integer value by
- accepting the dialog; for example, by clicking the \gui{OK} button.
+ accepting the dialog; for example, by clicking the \uicontrol{OK} button.
The selected value is specified by \a value.
This signal is only relevant when the input dialog is used in
\fn void QInputDialog::textValueSelected(const QString &text)
This signal is emitted whenever the user selects a text string by
- accepting the dialog; for example, by clicking the \gui{OK} button.
+ accepting the dialog; for example, by clicking the \uicontrol{OK} button.
The selected string is specified by \a text.
This signal is only relevant when the input dialog is used in
the message. The simplest configuration is to set only the
\l{QMessageBox::text} {message text} property.
- \snippet doc/src/snippets/code/src_gui_dialogs_qmessagebox.cpp 5
+ \snippet code/src_gui_dialogs_qmessagebox.cpp 5
- The user must click the \gui{OK} button to dismiss the message
+ The user must click the \uicontrol{OK} button to dismiss the message
box. The rest of the GUI is blocked until the message box is
dismissed.
responses. The buttons are specified by combining values from
StandardButtons using the bitwise OR operator. The display order
for the buttons is platform-dependent. For example, on Windows,
- \gui{Save} is displayed to the left of \gui{Cancel}, whereas on
+ \uicontrol{Save} is displayed to the left of \uicontrol{Cancel}, whereas on
Mac OS, the order is reversed.
Mark one of your standard buttons to be your
\l{QMessageBox::defaultButton()} {default button}.
- \snippet doc/src/snippets/code/src_gui_dialogs_qmessagebox.cpp 6
+ \snippet code/src_gui_dialogs_qmessagebox.cpp 6
This is the approach recommended in the
\l{http://developer.apple.com/library/mac/documentation/UserExperience/Conceptual/AppleHIGuidelines/Windows/Windows.html#//apple_ref/doc/uid/20000961-BABCAJID}
The exec() slot returns the StandardButtons value of the button
that was clicked.
- \snippet doc/src/snippets/code/src_gui_dialogs_qmessagebox.cpp 7
+ \snippet code/src_gui_dialogs_qmessagebox.cpp 7
To give the user more information to help him answer the question,
set the \l{QMessageBox::detailedText} {detailed text} property. If
the \l{QMessageBox::detailedText} {detailed text} property is set,
- the \gui{Show Details...} button will be shown.
+ the \uicontrol{Show Details...} button will be shown.
\image msgbox3.png
- Clicking the \gui{Show Details...} button displays the detailed text.
+ Clicking the \uicontrol{Show Details...} button displays the detailed text.
\image msgbox4.png
Static functions are available for creating information(),
question(), warning(), and critical() message boxes.
- \snippet doc/src/snippets/code/src_gui_dialogs_qmessagebox.cpp 0
+ \snippet code/src_gui_dialogs_qmessagebox.cpp 0
The \l{dialogs/standarddialogs}{Standard Dialogs} example shows
how to use QMessageBox and the other built-in Qt dialogs.
platform). You can test the value of clickedButton() after calling
exec(). For example,
- \snippet doc/src/snippets/code/src_gui_dialogs_qmessagebox.cpp 2
+ \snippet code/src_gui_dialogs_qmessagebox.cpp 2
\section1 Default and Escape Keys
Example:
- \snippet doc/src/snippets/code/src_gui_dialogs_qmessagebox.cpp 3
+ \snippet code/src_gui_dialogs_qmessagebox.cpp 3
\sa standardButton(), button()
*/
and centered over \a parent (if \a parent is not 0). The message
includes the version number of Qt being used by the application.
- This is useful for inclusion in the \gui Help menu of an application,
+ This is useful for inclusion in the \uicontrol Help menu of an application,
as shown in the \l{mainwindows/menus}{Menus} example.
QApplication provides this functionality as a slot.
to make it the cancel or close button (clicked when \key Esc is
pressed).
- \snippet doc/src/snippets/dialogs/dialogs.cpp 2
+ \snippet dialogs/dialogs.cpp 2
The message box is an \l{Qt::ApplicationModal} {application modal}
dialog box.
to use for the programmer. Do the operation in a loop, call \l setValue() at
intervals, and check for cancellation with wasCanceled(). For example:
- \snippet doc/src/snippets/dialogs/dialogs.cpp 3
+ \snippet dialogs/dialogs.cpp 3
A modeless progress dialog is suitable for operations that take
place in the background, where the user is able to interact with the
canceled() signal to a slot that stops the operation, and call \l
setValue() at intervals. For example:
- \snippet doc/src/snippets/dialogs/dialogs.cpp 4
+ \snippet dialogs/dialogs.cpp 4
\codeline
- \snippet doc/src/snippets/dialogs/dialogs.cpp 5
+ \snippet dialogs/dialogs.cpp 5
\codeline
- \snippet doc/src/snippets/dialogs/dialogs.cpp 6
+ \snippet dialogs/dialogs.cpp 6
In both modes the progress dialog may be customized by
replacing the child widgets with custom widgets by using setLabel(),
\l{dialogs/classwizard}{Class Wizard} and \l{dialogs/licensewizard}{License
Wizard}.
- \snippet examples/dialogs/trivialwizard/trivialwizard.cpp 1
- \snippet examples/dialogs/trivialwizard/trivialwizard.cpp 3
+ \snippet dialogs/trivialwizard/trivialwizard.cpp 1
+ \snippet dialogs/trivialwizard/trivialwizard.cpp 3
\dots
- \snippet examples/dialogs/trivialwizard/trivialwizard.cpp 4
+ \snippet dialogs/trivialwizard/trivialwizard.cpp 4
\codeline
- \snippet examples/dialogs/trivialwizard/trivialwizard.cpp 5
- \snippet examples/dialogs/trivialwizard/trivialwizard.cpp 7
+ \snippet dialogs/trivialwizard/trivialwizard.cpp 5
+ \snippet dialogs/trivialwizard/trivialwizard.cpp 7
\dots
- \snippet examples/dialogs/trivialwizard/trivialwizard.cpp 8
+ \snippet dialogs/trivialwizard/trivialwizard.cpp 8
\codeline
- \snippet examples/dialogs/trivialwizard/trivialwizard.cpp 10
+ \snippet dialogs/trivialwizard/trivialwizard.cpp 10
\section1 Wizard Look and Feel
In addition to the wizard style, there are several options that
control the look and feel of the wizard. These can be set using
setOption() or setOptions(). For example, HaveHelpButton makes
- QWizard show a \gui Help button along with the other wizard
+ QWizard show a \uicontrol Help button along with the other wizard
buttons.
You can even change the order of the wizard buttons to any
arbitrary order using setButtonLayout(), and you can add up to
- three custom buttons (e.g., a \gui Print button) to the button
+ three custom buttons (e.g., a \uicontrol Print button) to the button
row. This is achieved by calling setButton() or setButtonText()
with CustomButton1, CustomButton2, or CustomButton3 to set up the
button, and by enabling the HaveCustomButton1, HaveCustomButton2,
or HaveCustomButton3 options. Whenever the user clicks a custom
button, customButtonClicked() is emitted. For example:
- \snippet examples/dialogs/licensewizard/licensewizard.cpp 29
+ \snippet dialogs/licensewizard/licensewizard.cpp 29
\section1 Elements of a Wizard Page
To register a field, call QWizardPage::registerField() field.
For example:
- \snippet examples/dialogs/classwizard/classwizard.cpp 8
+ \snippet dialogs/classwizard/classwizard.cpp 8
\dots
- \snippet examples/dialogs/classwizard/classwizard.cpp 10
- \snippet examples/dialogs/classwizard/classwizard.cpp 11
+ \snippet dialogs/classwizard/classwizard.cpp 10
+ \snippet dialogs/classwizard/classwizard.cpp 11
\dots
- \snippet examples/dialogs/classwizard/classwizard.cpp 13
+ \snippet dialogs/classwizard/classwizard.cpp 13
The above code registers three fields, \c className, \c
baseClass, and \c qobjectMacro, which are associated with three
The fields of any page are accessible from any other page. For
example:
- \snippet examples/dialogs/classwizard/classwizard.cpp 17
+ \snippet dialogs/classwizard/classwizard.cpp 17
Here, we call QWizardPage::field() to access the contents of the
\c className field (which was defined in the \c ClassInfoPage)
If an asterisk (\c *) is appended to the name when the property
is registered, the field is a \e{mandatory field}. When a page has
- mandatory fields, the \gui Next and/or \gui Finish buttons are
+ mandatory fields, the \uicontrol Next and/or \uicontrol Finish buttons are
enabled only when all mandatory fields are filled.
To consider a field "filled", QWizard simply checks that the
QWizardPage::completeChanged() signal whenever the page becomes
complete or incomplete.
- The enabled/disabled state of the \gui Next and/or \gui Finish
+ The enabled/disabled state of the \uicontrol Next and/or \uicontrol Finish
buttons is one way to perform validation on the user input.
Another way is to reimplement validateCurrentPage() (or
QWizardPage::validatePage()) to perform some last-minute
them using addPage(). By default, the pages are shown in the
order in which they were added. For example:
- \snippet examples/dialogs/classwizard/classwizard.cpp 0
+ \snippet dialogs/classwizard/classwizard.cpp 0
\dots
- \snippet examples/dialogs/classwizard/classwizard.cpp 2
+ \snippet dialogs/classwizard/classwizard.cpp 2
When a page is about to be shown, QWizard calls initializePage()
(which in turn calls QWizardPage::initializePage()) to fill the
based on other pages' fields (see the \l{initialize page}{example
above}).
- If the user presses \gui Back, cleanupPage() is called (which in
+ If the user presses \uicontrol Back, cleanupPage() is called (which in
turn calls QWizardPage::cleanupPage()). The default
implementation resets the page's fields to their original values
(the values they had before initializePage() was called). If you
- want the \gui Back button to be non-destructive and keep the
+ want the \uicontrol Back button to be non-destructive and keep the
values entered by the user, simply enable the IndependentPages
option.
In complex wizards, pages are identified by IDs. These IDs are
typically defined using an enum. For example:
- \snippet examples/dialogs/licensewizard/licensewizard.h 0
+ \snippet dialogs/licensewizard/licensewizard.h 0
\dots
- \snippet examples/dialogs/licensewizard/licensewizard.h 2
+ \snippet dialogs/licensewizard/licensewizard.h 2
\dots
- \snippet examples/dialogs/licensewizard/licensewizard.h 3
+ \snippet dialogs/licensewizard/licensewizard.h 3
The pages are inserted using setPage(), which takes an ID and an
instance of QWizardPage (or of a subclass):
- \snippet examples/dialogs/licensewizard/licensewizard.cpp 1
+ \snippet dialogs/licensewizard/licensewizard.cpp 1
\dots
- \snippet examples/dialogs/licensewizard/licensewizard.cpp 8
+ \snippet dialogs/licensewizard/licensewizard.cpp 8
By default, the pages are shown in increasing ID order. To
provide a dynamic order that depends on the options chosen by the
user, we must reimplement QWizardPage::nextId(). For example:
- \snippet examples/dialogs/licensewizard/licensewizard.cpp 18
+ \snippet dialogs/licensewizard/licensewizard.cpp 18
\codeline
- \snippet examples/dialogs/licensewizard/licensewizard.cpp 23
+ \snippet dialogs/licensewizard/licensewizard.cpp 23
\codeline
- \snippet examples/dialogs/licensewizard/licensewizard.cpp 24
+ \snippet dialogs/licensewizard/licensewizard.cpp 24
\codeline
- \snippet examples/dialogs/licensewizard/licensewizard.cpp 25
+ \snippet dialogs/licensewizard/licensewizard.cpp 25
\codeline
- \snippet examples/dialogs/licensewizard/licensewizard.cpp 26
+ \snippet dialogs/licensewizard/licensewizard.cpp 26
It would also be possible to put all the logic in one place, in a
QWizard::nextId() reimplementation. For example:
- \snippet doc/src/snippets/code/src_gui_dialogs_qwizard.cpp 0
+ \snippet code/src_gui_dialogs_qwizard.cpp 0
To start at another page than the page with the lowest ID, call
setStartId().
To test whether a page has been visited or not, call
hasVisitedPage(). For example:
- \snippet examples/dialogs/licensewizard/licensewizard.cpp 27
+ \snippet dialogs/licensewizard/licensewizard.cpp 27
\sa QWizardPage, {Class Wizard Example}, {License Wizard Example}
*/
This enum specifies the buttons in a wizard.
- \value BackButton The \gui Back button (\gui {Go Back} on Mac OS X)
- \value NextButton The \gui Next button (\gui Continue on Mac OS X)
- \value CommitButton The \gui Commit button
- \value FinishButton The \gui Finish button (\gui Done on Mac OS X)
- \value CancelButton The \gui Cancel button (see also NoCancelButton)
- \value HelpButton The \gui Help button (see also HaveHelpButton)
+ \value BackButton The \uicontrol Back button (\uicontrol {Go Back} on Mac OS X)
+ \value NextButton The \uicontrol Next button (\uicontrol Continue on Mac OS X)
+ \value CommitButton The \uicontrol Commit button
+ \value FinishButton The \uicontrol Finish button (\uicontrol Done on Mac OS X)
+ \value CancelButton The \uicontrol Cancel button (see also NoCancelButton)
+ \value HelpButton The \uicontrol Help button (see also HaveHelpButton)
\value CustomButton1 The first user-defined button (see also HaveCustomButton1)
\value CustomButton2 The second user-defined button (see also HaveCustomButton2)
\value CustomButton3 The third user-defined button (see also HaveCustomButton3)
\value IgnoreSubTitles Don't show any subtitles, even if they are set.
\value ExtendedWatermarkPixmap Extend any WatermarkPixmap all the
way down to the window's edge.
- \value NoDefaultButton Don't make the \gui Next or \gui Finish button the
+ \value NoDefaultButton Don't make the \uicontrol Next or \uicontrol Finish button the
dialog's \l{QPushButton::setDefault()}{default button}.
- \value NoBackButtonOnStartPage Don't show the \gui Back button on the start page.
- \value NoBackButtonOnLastPage Don't show the \gui Back button on the last page.
- \value DisabledBackButtonOnLastPage Disable the \gui Back button on the last page.
- \value HaveNextButtonOnLastPage Show the (disabled) \gui Next button on the last page.
- \value HaveFinishButtonOnEarlyPages Show the (disabled) \gui Finish button on non-final pages.
- \value NoCancelButton Don't show the \gui Cancel button.
- \value CancelButtonOnLeft Put the \gui Cancel button on the left of \gui Back (rather than on
- the right of \gui Finish or \gui Next).
- \value HaveHelpButton Show the \gui Help button.
- \value HelpButtonOnRight Put the \gui Help button on the far right of the button layout
+ \value NoBackButtonOnStartPage Don't show the \uicontrol Back button on the start page.
+ \value NoBackButtonOnLastPage Don't show the \uicontrol Back button on the last page.
+ \value DisabledBackButtonOnLastPage Disable the \uicontrol Back button on the last page.
+ \value HaveNextButtonOnLastPage Show the (disabled) \uicontrol Next button on the last page.
+ \value HaveFinishButtonOnEarlyPages Show the (disabled) \uicontrol Finish button on non-final pages.
+ \value NoCancelButton Don't show the \uicontrol Cancel button.
+ \value CancelButtonOnLeft Put the \uicontrol Cancel button on the left of \uicontrol Back (rather than on
+ the right of \uicontrol Finish or \uicontrol Next).
+ \value HaveHelpButton Show the \uicontrol Help button.
+ \value HelpButtonOnRight Put the \uicontrol Help button on the far right of the button layout
(rather than on the far left).
\value HaveCustomButton1 Show the first user-defined button (CustomButton1).
\value HaveCustomButton2 Show the second user-defined button (CustomButton2).
Returns true if the page history contains page \a id; otherwise,
returns false.
- Pressing \gui Back marks the current page as "unvisited" again.
+ Pressing \uicontrol Back marks the current page as "unvisited" again.
\sa visitedPages()
*/
Returns the list of IDs of visited pages, in the order in which the pages
were visited.
- Pressing \gui Back marks the current page as "unvisited" again.
+ Pressing \uicontrol Back marks the current page as "unvisited" again.
\sa hasVisitedPage()
*/
Sets the text on button \a which to be \a text.
By default, the text on buttons depends on the wizardStyle. For
- example, on Mac OS X, the \gui Next button is called \gui
+ example, on Mac OS X, the \uicontrol Next button is called \uicontrol
Continue.
- To add extra buttons to the wizard (e.g., a \gui Print button),
+ To add extra buttons to the wizard (e.g., a \uicontrol Print button),
one way is to call setButtonText() with CustomButton1,
CustomButton2, or CustomButton3 to set their text, and make the
buttons visible using the HaveCustomButton1, HaveCustomButton2,
If a text has ben set using setButtonText(), this text is returned.
By default, the text on buttons depends on the wizardStyle. For
- example, on Mac OS X, the \gui Next button is called \gui
+ example, on Mac OS X, the \uicontrol Next button is called \uicontrol
Continue.
\sa button(), setButton(), setButtonText(), QWizardPage::buttonText(),
Example:
- \snippet doc/src/snippets/code/src_gui_dialogs_qwizard.cpp 1
+ \snippet code/src_gui_dialogs_qwizard.cpp 1
\sa setButton(), setButtonText(), setOptions()
*/
/*!
Sets the button corresponding to role \a which to \a button.
- To add extra buttons to the wizard (e.g., a \gui Print button),
+ To add extra buttons to the wizard (e.g., a \uicontrol Print button),
one way is to call setButton() with CustomButton1 to
CustomButton3, and make the buttons visible using the
HaveCustomButton1 to HaveCustomButton3 options.
/*!
\fn void QWizard::helpRequested()
- This signal is emitted when the user clicks the \gui Help button.
+ This signal is emitted when the user clicks the \uicontrol Help button.
- By default, no \gui Help button is shown. Call
+ By default, no \uicontrol Help button is shown. Call
setOption(HaveHelpButton, true) to have one.
Example:
- \snippet examples/dialogs/licensewizard/licensewizard.cpp 0
+ \snippet dialogs/licensewizard/licensewizard.cpp 0
\dots
- \snippet examples/dialogs/licensewizard/licensewizard.cpp 5
- \snippet examples/dialogs/licensewizard/licensewizard.cpp 7
+ \snippet dialogs/licensewizard/licensewizard.cpp 5
+ \snippet dialogs/licensewizard/licensewizard.cpp 7
\dots
- \snippet examples/dialogs/licensewizard/licensewizard.cpp 8
+ \snippet dialogs/licensewizard/licensewizard.cpp 8
\codeline
- \snippet examples/dialogs/licensewizard/licensewizard.cpp 10
+ \snippet dialogs/licensewizard/licensewizard.cpp 10
\dots
- \snippet examples/dialogs/licensewizard/licensewizard.cpp 12
+ \snippet dialogs/licensewizard/licensewizard.cpp 12
\codeline
- \snippet examples/dialogs/licensewizard/licensewizard.cpp 14
+ \snippet dialogs/licensewizard/licensewizard.cpp 14
\codeline
- \snippet examples/dialogs/licensewizard/licensewizard.cpp 15
+ \snippet dialogs/licensewizard/licensewizard.cpp 15
\sa customButtonClicked()
*/
/*!
Goes back to the previous page.
- This is equivalent to pressing the \gui Back button.
+ This is equivalent to pressing the \uicontrol Back button.
\sa next(), accept(), reject(), restart()
*/
/*!
Advances to the next page.
- This is equivalent to pressing the \gui Next or \gui Commit button.
+ This is equivalent to pressing the \uicontrol Next or \uicontrol Commit button.
\sa nextId(), back(), accept(), reject(), restart()
*/
This virtual function is called by QWizard to prepare page \a id
just before it is shown either as a result of QWizard::restart()
- being called, or as a result of the user clicking \gui Next. (However, if the \l
+ being called, or as a result of the user clicking \uicontrol Next. (However, if the \l
QWizard::IndependentPages option is set, this function is only
called the first time the page is shown.)
\fn void QWizard::cleanupPage(int id)
This virtual function is called by QWizard to clean up page \a id just before the
- user leaves it by clicking \gui Back (unless the \l QWizard::IndependentPages option is set).
+ user leaves it by clicking \uicontrol Back (unless the \l QWizard::IndependentPages option is set).
The default implementation calls QWizardPage::cleanupPage() on
page(\a id).
/*!
This virtual function is called by QWizard when the user clicks
- \gui Next or \gui Finish to perform some last-minute validation.
+ \uicontrol Next or \uicontrol Finish to perform some last-minute validation.
If it returns true, the next page is shown (or the wizard
finishes); otherwise, the current page stays up.
The default implementation calls QWizardPage::validatePage() on
the currentPage().
- When possible, it is usually better style to disable the \gui
- Next or \gui Finish button (by specifying \l{mandatory fields} or
+ When possible, it is usually better style to disable the \uicontrol
+ Next or \uicontrol Finish button (by specifying \l{mandatory fields} or
by reimplementing QWizardPage::isComplete()) than to reimplement
validateCurrentPage().
/*!
This virtual function is called by QWizard to find out which page
- to show when the user clicks the \gui Next button.
+ to show when the user clicks the \uicontrol Next button.
The return value is the ID of the next page, or -1 if no page follows.
\list
\li initializePage() is called to initialize the page's contents
- when the user clicks the wizard's \gui Next button. If you
+ when the user clicks the wizard's \uicontrol Next button. If you
want to derive the page's default from what the user entered
on previous pages, this is the function to reimplement.
\li cleanupPage() is called to reset the page's contents when the
- user clicks the wizard's \gui Back button.
- \li validatePage() validates the page when the user clicks \gui
- Next or \gui Finish. It is often used to show an error message
+ user clicks the wizard's \uicontrol Back button.
+ \li validatePage() validates the page when the user clicks \uicontrol
+ Next or \uicontrol Finish. It is often used to show an error message
if the user has entered incomplete or invalid information.
\li nextId() returns the ID of the next page. It is useful when
\l{creating non-linear wizards}, which allow different
traversal paths based on the information provided by the user.
- \li isComplete() is called to determine whether the \gui Next
- and/or \gui Finish button should be enabled or disabled. If
+ \li isComplete() is called to determine whether the \uicontrol Next
+ and/or \uicontrol Finish button should be enabled or disabled. If
you reimplement isComplete(), also make sure that
completeChanged() is emitted whenever the complete state
changes.
\endlist
- Normally, the \gui Next button and the \gui Finish button of a
- wizard are mutually exclusive. If isFinalPage() returns true, \gui
- Finish is available; otherwise, \gui Next is available. By
+ Normally, the \uicontrol Next button and the \uicontrol Finish button of a
+ wizard are mutually exclusive. If isFinalPage() returns true, \uicontrol
+ Finish is available; otherwise, \uicontrol Next is available. By
default, isFinalPage() is true only when nextId() returns -1. If
- you want to show \gui Next and \gui Final simultaneously for a
+ you want to show \uicontrol Next and \uicontrol Final simultaneously for a
page (letting the user perform an "early finish"), call
setFinalPage(true) on that page. For wizards that support early
finishes, you might also want to set the
/*!
This virtual function is called by QWizard::initializePage() to
prepare the page just before it is shown either as a result of QWizard::restart()
- being called, or as a result of the user clicking \gui Next.
+ being called, or as a result of the user clicking \uicontrol Next.
(However, if the \l QWizard::IndependentPages option is set, this function is only
called the first time the page is shown.)
fields are properly initialized based on fields from previous
pages. For example:
- \snippet examples/dialogs/classwizard/classwizard.cpp 17
+ \snippet dialogs/classwizard/classwizard.cpp 17
The default implementation does nothing.
/*!
This virtual function is called by QWizard::cleanupPage() when
- the user leaves the page by clicking \gui Back (unless the \l QWizard::IndependentPages
+ the user leaves the page by clicking \uicontrol Back (unless the \l QWizard::IndependentPages
option is set).
The default implementation resets the page's fields to their
/*!
This virtual function is called by QWizard::validateCurrentPage()
- when the user clicks \gui Next or \gui Finish to perform some
+ when the user clicks \uicontrol Next or \uicontrol Finish to perform some
last-minute validation. If it returns true, the next page is shown
(or the wizard finishes); otherwise, the current page stays up.
The default implementation returns true.
- When possible, it is usually better style to disable the \gui
- Next or \gui Finish button (by specifying \l{mandatory fields} or
+ When possible, it is usually better style to disable the \uicontrol
+ Next or \uicontrol Finish button (by specifying \l{mandatory fields} or
reimplementing isComplete()) than to reimplement validatePage().
\sa QWizard::validateCurrentPage(), isComplete()
/*!
This virtual function is called by QWizard to determine whether
- the \gui Next or \gui Finish button should be enabled or
+ the \uicontrol Next or \uicontrol Finish button should be enabled or
disabled.
The default implementation returns true if all \l{mandatory
/*!
Explicitly sets this page to be final if \a finalPage is true.
- After calling setFinalPage(true), isFinalPage() returns true and the \gui
+ After calling setFinalPage(true), isFinalPage() returns true and the \uicontrol
Finish button is visible (and enabled if isComplete() returns
true).
}
/*!
- This function is called by QWizard to determine whether the \gui
+ This function is called by QWizard to determine whether the \uicontrol
Finish button should be shown for this page or not.
By default, it returns true if there is no next page
sets it to be a normal page.
A commit page is a page that represents an action which cannot be undone
- by clicking \gui Back or \gui Cancel.
+ by clicking \uicontrol Back or \uicontrol Cancel.
- A \gui Commit button replaces the \gui Next button on a commit page. Clicking this
- button simply calls QWizard::next() just like clicking \gui Next does.
+ A \uicontrol Commit button replaces the \uicontrol Next button on a commit page. Clicking this
+ button simply calls QWizard::next() just like clicking \uicontrol Next does.
- A page entered directly from a commit page has its \gui Back button disabled.
+ A page entered directly from a commit page has its \uicontrol Back button disabled.
\sa isCommitPage()
*/
this text is returned.
By default, the text on buttons depends on the QWizard::wizardStyle.
- For example, on Mac OS X, the \gui Next button is called \gui
+ For example, on Mac OS X, the \uicontrol Next button is called \uicontrol
Continue.
\sa setButtonText(), QWizard::buttonText(), QWizard::setButtonText()
/*!
This virtual function is called by QWizard::nextId() to find
- out which page to show when the user clicks the \gui Next button.
+ out which page to show when the user clicks the \uicontrol Next button.
The return value is the ID of the next page, or -1 if no page follows.
By reimplementing this function, you can specify a dynamic page
order. For example:
- \snippet examples/dialogs/licensewizard/licensewizard.cpp 18
+ \snippet dialogs/licensewizard/licensewizard.cpp 18
\sa QWizard::nextId()
*/
Example:
- \snippet examples/dialogs/classwizard/classwizard.cpp 17
+ \snippet dialogs/classwizard/classwizard.cpp 17
\sa QWizard::field(), setField(), registerField()
*/
explicitly about each other.
If \a name ends with an asterisk (\c *), the field is a mandatory
- field. When a page has mandatory fields, the \gui Next and/or
- \gui Finish buttons are enabled only when all mandatory fields
+ field. When a page has mandatory fields, the \uicontrol Next and/or
+ \uicontrol Finish buttons are enabled only when all mandatory fields
are filled. This requires a \a changedSignal to be specified, to
tell QWizard to recheck the value stored by the mandatory field.
--- /dev/null
+include(../../../doc/global/qt-cpp-ignore.qdocconf)
+
+project = QtWidgets
+description = Qt Widgets Reference Documentation
+url = http://qt-project.org/doc/qt-5.0/qtwidgets
+version = 5.0.0
+
+sourceencoding = UTF-8
+outputencoding = UTF-8
+naturallanguage = en_US
+qhp.projects = QtWidgets
+
+qhp.QtWidgets.file = qtwidgets.qhp
+qhp.QtWidgets.namespace = org.qt-project.qtwidgets.500
+qhp.QtWidgets.virtualFolder = qdoc
+qhp.QtWidgets.indexTitle = Qt Widgets Reference Documentation
+qhp.QtWidgets.indexRoot =
+
+qhp.QtWidgets.filterAttributes = qtwidgets 5.0.0 qtrefdoc
+qhp.QtWidgets.customFilters.Qt.name = QtWidgets 5.0.0
+qhp.QtWidgets.customFilters.Qt.filterAttributes = qtwidgets 5.0.0
+qhp.QtWidgets.subprojects = classes overviews examples
+qhp.QtWidgets.subprojects.classes.title = Classes
+qhp.QtWidgets.subprojects.classes.indexTitle = Qt Widgets' Classes
+qhp.QtWidgets.subprojects.classes.selectors = class fake:headerfile
+qhp.QtWidgets.subprojects.classes.sortPages = true
+qhp.QtWidgets.subprojects.overviews.title = Overviews
+qhp.QtWidgets.subprojects.overviews.indexTitle = All Overviews and HOWTOs
+qhp.QtWidgets.subprojects.overviews.selectors = fake:page,group,module
+qhp.QtWidgets.subprojects.examples.title = Qt Widgets Examples
+qhp.QtWidgets.subprojects.examples.indexTitle = Qt Widgets Examples
+qhp.QtWidgets.subprojects.examples.selectors = fake:example
+
+dita.metadata.default.author = Qt Project
+dita.metadata.default.permissions = all
+dita.metadata.default.publisher = Qt Project
+dita.metadata.default.copyryear = 2012
+dita.metadata.default.copyrholder = Nokia
+dita.metadata.default.audience = programmer
+
+sources.fileextensions = "*.c++ *.cc *.cpp *.cxx *.mm *.qml *.qdoc"
+headers.fileextensions = "*.ch *.h *.h++ *.hh *.hpp *.hxx"
+
+examples.fileextensions = "*.cpp *.h *.js *.xq *.svg *.xml *.ui *.qhp *.qhcp *.qml *.css"
+examples.imageextensions = "*.png"
+
+outputdir = ../../../doc/qtwidgets
+tagfile = ../../../doc/qtwidgets/qtwidgets.tags
+
+HTML.generatemacrefs = "true"
+HTML.nobreadcrumbs = "true"
+
+HTML.templatedir = .
+
+HTML.stylesheets = ../../../doc/global/style/offline.css
+
+HTML.headerstyles = \
+ " <link rel=\"stylesheet\" type=\"text/css\" href=\"style/offline.css\" />\n"
+
+HTML.endheader = \
+ "</head>\n" \
+
+defines = Q_QDOC \
+ QT_.*_SUPPORT \
+ QT_.*_LIB \
+ QT_COMPAT \
+ QT_KEYPAD_NAVIGATION \
+ QT_NO_EGL \
+ Q_WS_.* \
+ Q_OS_.* \
+ Q_BYTE_ORDER \
+ QT_DEPRECATED \
+ QT_DEPRECATED_* \
+ Q_NO_USING_KEYWORD \
+ __cplusplus \
+ Q_COMPILER_INITIALIZER_LISTS
+
+versionsym = QT_VERSION_STR
+
+codeindent = 1
+
+depends += qtcore qtgui
+
+headerdirs += ..
+
+sourcedirs += ..
+
+exampledirs += ../../../examples \
+ ../ \
+ snippets
+
+imagedirs += images
--- /dev/null
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [1]
+#include <QtWidgets>
+//! [1]
--- /dev/null
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#! [0]
+QT += widgets
+#! [0]
--- /dev/null
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [0]
+int ret = QMessageBox::warning(this, tr("My Application"),
+ tr("The document has been modified.\n"
+ "Do you want to save your changes?"),
+ QMessageBox::Save | QMessageBox::Discard
+ | QMessageBox::Cancel,
+ QMessageBox::Save);
+//! [0]
+
+
+//! [1]
+QMessageBox msgBox;
+msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+switch (msgBox.exec()) {
+case QMessageBox::Yes:
+ // yes was clicked
+ break;
+case QMessageBox::No:
+ // no was clicked
+ break;
+default:
+ // should never be reached
+ break;
+}
+//! [1]
+
+
+//! [2]
+QMessageBox msgBox;
+QPushButton *connectButton = msgBox.addButton(tr("Connect"), QMessageBox::ActionRole);
+QPushButton *abortButton = msgBox.addButton(QMessageBox::Abort);
+
+msgBox.exec();
+
+if (msgBox.clickedButton() == connectButton) {
+ // connect
+} else if (msgBox.clickedButton() == abortButton) {
+ // abort
+}
+//! [2]
+
+
+//! [3]
+QMessageBox messageBox(this);
+QAbstractButton *disconnectButton =
+ messageBox.addButton(tr("Disconnect"), QMessageBox::ActionRole);
+...
+messageBox.exec();
+if (messageBox.clickedButton() == disconnectButton) {
+ ...
+}
+//! [3]
+
+
+//! [4]
+#include <QApplication>
+#include <QMessageBox>
+
+int main(int argc, char *argv[])
+{
+ QT_REQUIRE_VERSION(argc, argv, "4.0.2")
+
+ QApplication app(argc, argv);
+ ...
+ return app.exec();
+}
+//! [4]
+
+//! [5]
+QMessageBox msgBox;
+msgBox.setText("The document has been modified.");
+msgBox.exec();
+//! [5]
+
+//! [6]
+QMessageBox msgBox;
+msgBox.setText("The document has been modified.");
+msgBox.setInformativeText("Do you want to save your changes?");
+msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
+msgBox.setDefaultButton(QMessageBox::Save);
+int ret = msgBox.exec();
+//! [6]
+
+//! [7]
+switch (ret) {
+ case QMessageBox::Save:
+ // Save was clicked
+ break;
+ case QMessageBox::Discard:
+ // Don't Save was clicked
+ break;
+ case QMessageBox::Cancel:
+ // Cancel was clicked
+ break;
+ default:
+ // should never be reached
+ break;
+}
+//! [7]
+
+//! [9]
+QMessageBox msgBox(this);
+msgBox.setText(tr("The document has been modified.\n"
+ "Do you want to save your changes?"));
+msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard
+ | QMessageBox::Cancel);
+msgBox.setDefaultButton(QMessageBox::Save);
+//! [9]
--- /dev/null
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [0]
+int main(int argc, char **argv)
+{
+#ifdef Q_WS_X11
+ bool useGUI = getenv("DISPLAY") != 0;
+#else
+ bool useGUI = true;
+#endif
+ QApplication app(argc, argv, useGUI);
+
+ if (useGUI) {
+ // start GUI version
+ ...
+ } else {
+ // start non-GUI version
+ ...
+ }
+ return app.exec();
+}
+//! [0]
+
+
+//! [1]
+QApplication::setStyle(new QWindowsStyle);
+//! [1]
+
+
+//! [2]
+int main(int argc, char *argv[])
+{
+ QApplication::setColorSpec(QApplication::ManyColor);
+ QApplication app(argc, argv);
+ ...
+ return app.exec();
+}
+//! [2]
+
+
+//! [3]
+QSize MyWidget::sizeHint() const
+{
+ return QSize(80, 25).expandedTo(QApplication::globalStrut());
+}
+//! [3]
+
+
+//! [4]
+void showAllHiddenTopLevelWidgets()
+{
+ foreach (QWidget *widget, QApplication::topLevelWidgets()) {
+ if (widget->isHidden())
+ widget->show();
+ }
+}
+//! [4]
+
+
+//! [5]
+void updateAllWidgets()
+{
+ foreach (QWidget *widget, QApplication::allWidgets())
+ widget->update();
+}
+//! [5]
+
+
+//! [6]
+int main(int argc, char *argv[])
+{
+ QApplication::setDesktopSettingsAware(false);
+ QApplication app(argc, argv);
+ ...
+ return app.exec();
+}
+//! [6]
+
+
+//! [7]
+if ((startPos - currentPos).manhattanLength() >=
+ QApplication::startDragDistance())
+ startTheDrag();
+//! [7]
+
+
+//! [8]
+void MyApplication::commitData(QSessionManager& manager)
+{
+ if (manager.allowsInteraction()) {
+ int ret = QMessageBox::warning(
+ mainWindow,
+ tr("My Application"),
+ tr("Save changes to document?"),
+ QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
+
+ switch (ret) {
+ case QMessageBox::Save:
+ manager.release();
+ if (!saveDocument())
+ manager.cancel();
+ break;
+ case QMessageBox::Discard:
+ break;
+ case QMessageBox::Cancel:
+ default:
+ manager.cancel();
+ }
+ } else {
+ // we did not get permission to interact, then
+ // do something reasonable instead
+ }
+}
+//! [8]
+
+
+//! [9]
+appname -session id
+//! [9]
+
+
+//! [10]
+foreach (const QString &command, mySession.restartCommand())
+ do_something(command);
+//! [10]
+
+
+//! [11]
+foreach (const QString &command, mySession.discardCommand())
+ do_something(command);
+//! [11]
+
+
+//! [12]
+QWidget *widget = qApp->widgetAt(x, y);
+if (widget)
+ widget = widget->window();
+//! [12]
+
+
+//! [13]
+QWidget *widget = qApp->widgetAt(point);
+if (widget)
+ widget = widget->window();
+//! [13]
--- /dev/null
+HEADERS += customstyle.h
+SOURCES += customstyle.cpp main.cpp
--- /dev/null
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [using a custom style]
+#include <QtGui>
+
+#include "customstyle.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication::setStyle(new CustomStyle);
+ QApplication app(argc, argv);
+ QSpinBox spinBox;
+ spinBox.show();
+ return app.exec();
+}
+//! [using a custom style]
To include the definitions of the module's classes, use the
following directive:
- \snippet doc/src/snippets/code/doc_src_qtwidgets.cpp 1
+ \snippet code/doc_src_qtwidgets.cpp 1
To link against the module, add this line to your \l qmake \c
.pro file:
- \snippet doc/src/snippets/code/doc_src_qtwidgets.pro 0
+ \snippet code/doc_src_qtwidgets.pro 0
*/
The following code creates a QHBoxLayout that manages the geometry of five
\l{QPushButton}{QPushButtons}, as shown on the first screenshot above:
- \snippet doc/src/snippets/layouts/layouts.cpp 0
- \snippet doc/src/snippets/layouts/layouts.cpp 1
- \snippet doc/src/snippets/layouts/layouts.cpp 2
+ \snippet layouts/layouts.cpp 0
+ \snippet layouts/layouts.cpp 1
+ \snippet layouts/layouts.cpp 2
\codeline
- \snippet doc/src/snippets/layouts/layouts.cpp 3
- \snippet doc/src/snippets/layouts/layouts.cpp 4
- \snippet doc/src/snippets/layouts/layouts.cpp 5
+ \snippet layouts/layouts.cpp 3
+ \snippet layouts/layouts.cpp 4
+ \snippet layouts/layouts.cpp 5
The code for QVBoxLayout is identical, except the line where the layout is
created. The code for QGridLayout is a bit different, because we need to
specify the row and column position of the child widget:
- \snippet doc/src/snippets/layouts/layouts.cpp 12
- \snippet doc/src/snippets/layouts/layouts.cpp 13
- \snippet doc/src/snippets/layouts/layouts.cpp 14
+ \snippet layouts/layouts.cpp 12
+ \snippet layouts/layouts.cpp 13
+ \snippet layouts/layouts.cpp 14
\codeline
- \snippet doc/src/snippets/layouts/layouts.cpp 15
- \snippet doc/src/snippets/layouts/layouts.cpp 16
- \snippet doc/src/snippets/layouts/layouts.cpp 17
+ \snippet layouts/layouts.cpp 15
+ \snippet layouts/layouts.cpp 16
+ \snippet layouts/layouts.cpp 17
The third QPushButton spans 2 columns. This is possible by specifying 2 as
the fifth argument to QGridLayout::addWidget().
QFormLayout to place three \l{QPushButton}{QPushButtons} and a corresponding
QLineEdit on a row.
- \snippet doc/src/snippets/layouts/layouts.cpp 18
- \snippet doc/src/snippets/layouts/layouts.cpp 19
- \snippet doc/src/snippets/layouts/layouts.cpp 20
+ \snippet layouts/layouts.cpp 18
+ \snippet layouts/layouts.cpp 19
+ \snippet layouts/layouts.cpp 20
\codeline
- \snippet doc/src/snippets/layouts/layouts.cpp 21
- \snippet doc/src/snippets/layouts/layouts.cpp 22
- \snippet doc/src/snippets/layouts/layouts.cpp 23
+ \snippet layouts/layouts.cpp 21
+ \snippet layouts/layouts.cpp 22
+ \snippet layouts/layouts.cpp 23
\section2 Tips for Using Layouts
\section2 The Header File (\c card.h)
- \snippet doc/src/snippets/code/doc_src_layout.cpp 0
+ \snippet code/doc_src_layout.cpp 0
\section2 The Implementation File (\c card.cpp)
- \snippet doc/src/snippets/code/doc_src_layout.cpp 1
+ \snippet code/doc_src_layout.cpp 1
First we define \c{count()} to fetch the number of items in the list.
- \snippet doc/src/snippets/code/doc_src_layout.cpp 2
+ \snippet code/doc_src_layout.cpp 2
Then we define two functions that iterate over the layout: \c{itemAt()}
and \c{takeAt()}. These functions are used internally by the layout system
structure, we may have to spend more effort defining a linear order for the
items.
- \snippet doc/src/snippets/code/doc_src_layout.cpp 3
+ \snippet code/doc_src_layout.cpp 3
\c{addItem()} implements the default placement strategy for layout items.
This function must be implemented. It is used by QLayout::add(), by the
QGridLayout::addItem(), QGridLayout::addWidget(), and
QGridLayout::addLayout().
- \snippet doc/src/snippets/code/doc_src_layout.cpp 4
+ \snippet code/doc_src_layout.cpp 4
The layout takes over responsibility of the items added. Since QLayoutItem
does not inherit QObject, we must delete the items manually. In the
destructor, we remove each item from the list using \c{takeAt()}, and
then delete it.
- \snippet doc/src/snippets/code/doc_src_layout.cpp 5
+ \snippet code/doc_src_layout.cpp 5
The \c{setGeometry()} function actually performs the layout. The rectangle
supplied as an argument does not include \c{margin()}. If relevant, use
\c{spacing()} as the distance between items.
- \snippet doc/src/snippets/code/doc_src_layout.cpp 6
+ \snippet code/doc_src_layout.cpp 6
\c{sizeHint()} and \c{minimumSize()} are normally very similar in
implementation. The sizes returned by both functions should include
\c{spacing()}, but not \c{margin()}.
- \snippet doc/src/snippets/code/doc_src_layout.cpp 7
+ \snippet code/doc_src_layout.cpp 7
\section2 Further Notes
pointer type is correct. If the object isn't of the right type,
qstyleoption_cast() returns 0. For example:
- \snippet doc/src/snippets/code/doc_src_qt4-styles.cpp 0
+ \snippet code/doc_src_qt4-styles.cpp 0
The following code snippet illustrates how to use QStyle to
draw the focus rectangle from a custom widget's paintEvent():
- \snippet doc/src/snippets/code/doc_src_qt4-styles.cpp 1
+ \snippet code/doc_src_qt4-styles.cpp 1
The next example shows how to derive from an existing style to
customize the look of a graphical element:
- \snippet doc/src/snippets/customstyle/customstyle.h 0
+ \snippet customstyle/customstyle.h 0
\codeline
- \snippet doc/src/snippets/customstyle/customstyle.cpp 2
- \snippet doc/src/snippets/customstyle/customstyle.cpp 3
- \snippet doc/src/snippets/customstyle/customstyle.cpp 4
+ \snippet customstyle/customstyle.cpp 2
+ \snippet customstyle/customstyle.cpp 3
+ \snippet customstyle/customstyle.cpp 4
\section2 QStyle Functions
We start with a look at how QCheckBox builds it style option,
which is QStyleOptionButton for checkboxes:
- \snippet doc/src/snippets/code/doc_src_styles.cpp 0
+ \snippet code/doc_src_styles.cpp 0
First we let QStyleOption set up the option with the information
that is common for all widgets with \c initFrom(). We will look at
attributes that are common for all widgets. We print its
implementation here:
- \snippet doc/src/snippets/code/doc_src_styles.cpp 1
+ \snippet code/doc_src_styles.cpp 1
The State_Enabled is set when the widget is enabled. When the
widget has focus the State_HasFocus flag is set. Equally, the
notably, it wraps the methods in QStyle used for painting. The
QCheckBox draws itself as follows:
- \snippet doc/src/snippets/code/doc_src_styles.cpp 2
+ \snippet code/doc_src_styles.cpp 2
QCommonStyle handles the CE_CheckBox element. The QCheckBox
has two sub elements: SE_CheckBoxIndicator (the checked indicator)
checkbox label). QCommonStyle also implements these sub element
bounding rectangles. We have a look at the QCommonStyle code:
- \snippet doc/src/snippets/code/doc_src_styles.cpp 3
+ \snippet code/doc_src_styles.cpp 3
As can be seen from the code extract, the common style gets
the bounding rectangles of the two sub elements of
handles CE_CheckboxLabel. We will examine each implementation and
start with CE_CheckBoxLabel:
- \snippet doc/src/snippets/code/doc_src_styles.cpp 4
+ \snippet code/doc_src_styles.cpp 4
\l{QStyle::}{visualAlignment()} adjusts the alignment of text
according to the layout direction. We then draw an icon if it
We take a look at the java implementation
of CE_CheckBoxIndicator in \c drawControl():
- \snippet doc/src/snippets/javastyle.cpp 0
+ \snippet javastyle.cpp 0
We first save the state of the painter. This is not always
necessary but in this case the QWindowsStyle needs the painter in
here if the widget is disabled. We would then have to use
another image with the indicator in the disabled color.
- \snippet doc/src/snippets/javastyle.cpp 1
+ \snippet javastyle.cpp 1
We have seen how check boxes are styled in the java style from the
widget gets a paint request to the style is finished painting. To
\l{QLineEdit}s should use yellow as their background color, and
all \l{QCheckBox}es should use red as the text color:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 0
+ \snippet code/doc_src_stylesheet.qdoc 0
For this kind of customization, style sheets are much more
powerful than QPalette. For example, it might be tempting to set
the \e{declaration} specifies which properties should be set on
the widget. For example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 1
+ \snippet code/doc_src_stylesheet.qdoc 1
In the above style rule, \c QPushButton is the selector and \c{{
color: red }} is the declaration. The rule specifies that
using commas (\c{,}) to separate the selectors. For example,
the rule
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 2
+ \snippet code/doc_src_stylesheet.qdoc 2
is equivalent to this sequence of three rules:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 3
+ \snippet code/doc_src_stylesheet.qdoc 3
The declaration part of a style rule is a list of
\tt{\e{property}: \e{value}} pairs, enclosed in braces (\c{{}})
and separated with semicolons. For example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 4
+ \snippet code/doc_src_stylesheet.qdoc 4
See the \l{List of Properties} section below for the list of
properties provided by Qt widgets.
possible to restrict the application of a rule to specific widget
subcontrols. For example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 5
+ \snippet code/doc_src_stylesheet.qdoc 5
The above rule styles the drop-down button of all \l{QComboBox}es.
Although the double-colon (\c{::}) syntax is reminiscent of CSS3
rectangle of the QComboBox instead of the default Padding rectangle, we
can specify:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 6
+ \snippet code/doc_src_stylesheet.qdoc 6
The alignment of the drop-down within the Margin rectangle is changed
using \l{Qt Style Sheets Reference#subcontrol-position-prop}
pressed, we might like the arrow inside to be offset to give a
"pressed" effect. To achieve this, we can specify:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 7
+ \snippet code/doc_src_stylesheet.qdoc 7
The absolute positioning scheme
(\l{Qt Style Sheets Reference#position-prop}{position} : absolute),
(\c{:}) in between. For example, the following rule applies when
the mouse hovers over a QPushButton:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 8
+ \snippet code/doc_src_stylesheet.qdoc 8
Pseudo-states can be negated using the exclamation operator. For
example, the following rule applies when the mouse does not hover
over a QRadioButton:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 9
+ \snippet code/doc_src_stylesheet.qdoc 9
Pseudo-states can be chained, in which case a logical AND is
implied. For example, the following rule applies to when the
mouse hovers over a checked QCheckBox:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 10
+ \snippet code/doc_src_stylesheet.qdoc 10
Negated Pseudo-states may appear in Pseudo-state chains. For example,
the following rule applies when the mouse hovers over a QPushButton
that is not pressed:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 11
+ \snippet code/doc_src_stylesheet.qdoc 11
If needed, logical OR can be expressed using the comma operator:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 12
+ \snippet code/doc_src_stylesheet.qdoc 12
Pseudo-states can appear in combination with subcontrols. For
example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 13
+ \snippet code/doc_src_stylesheet.qdoc 13
See the \l{List of Pseudo-States} section below for the list of
pseudo-states provided by Qt widgets.
properties with different values. Consider the following style
sheet:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 14
+ \snippet code/doc_src_stylesheet.qdoc 14
Both rules match QPushButton instances called \c okButton and
there is a conflict for the \c color property. To resolve this
sheet specifies that a \l{QPushButton} should have white text
when the mouse is hovering over it, otherwise red text:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 15
+ \snippet code/doc_src_stylesheet.qdoc 15
Here's a tricky one:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 16
+ \snippet code/doc_src_stylesheet.qdoc 16
Here, both selectors have the same specificity, so if the mouse
hovers over the button while it is enabled, the second rule takes
precedence. If we want the text to be white in that case, we can
reorder the rules like this:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 17
+ \snippet code/doc_src_stylesheet.qdoc 17
Alternatively, we can make the first rule more specific:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 18
+ \snippet code/doc_src_stylesheet.qdoc 18
A similar issue arises in conjunction with Type Selectors.
Consider the following example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 19
+ \snippet code/doc_src_stylesheet.qdoc 19
Both rules apply to QPushButton instances (since QPushButton
inherits QAbstractButton) and there is a conflict for the
\e{Some examples:}
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 20
+ \snippet code/doc_src_stylesheet.qdoc 20
\endquotation
\section1 Cascading
sheet. Consider the following example. First, we set a style
sheet on the QApplication:
- \snippet doc/src/snippets/code/doc_src_stylesheet.cpp 21
+ \snippet code/doc_src_stylesheet.cpp 21
Then we set a style sheet on a QPushButton object:
- \snippet doc/src/snippets/code/doc_src_stylesheet.cpp 22
+ \snippet code/doc_src_stylesheet.cpp 22
The style sheet on the QPushButton forces the QPushButton (and
any child widget) to have blue text, in spite of the more
The result would have been the same if we had written
- \snippet doc/src/snippets/code/doc_src_stylesheet.cpp 23
+ \snippet code/doc_src_stylesheet.cpp 23
except that if the QPushButton had children (which is unlikely),
the style sheet would have no impact on them.
For example, consider a QPushButton inside a QGroupBox:
- \snippet doc/src/snippets/code/doc_src_stylesheet.cpp 24
+ \snippet code/doc_src_stylesheet.cpp 24
The QPushButton does not have an explicit color set. Hence, instead
of inheriting color of its parent QGroupBox, it has the system color.
If we want to set the color on a QGroupBox and its children,
we can write:
- \snippet doc/src/snippets/code/doc_src_stylesheet.cpp 25
+ \snippet code/doc_src_stylesheet.cpp 25
In contrast, setting a font and propagate using QWidget::setFont() and
QWidget::setPalette() propagates to child widgets.
The Type Selector can be used to style widgets of a particular type. For
example,
- \snippet doc/src/snippets/code/doc_src_stylesheet.cpp 26
+ \snippet code/doc_src_stylesheet.cpp 26
Qt Style Sheet uses QObject::className() of the widget to determine
when to apply the Type Selector. When custom widgets are inside namespaces,
when using the Type Selector for widgets inside namespaces, we must
replace the "::" with "--". For example,
- \snippet doc/src/snippets/code/doc_src_stylesheet.cpp 27
+ \snippet code/doc_src_stylesheet.cpp 27
\section1 Setting QObject properties
can be set using the qproperty-<property name> syntax.
For example,
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 28
+ \snippet code/doc_src_stylesheet.qdoc 28
If the property references an enum declared with Q_ENUMS, you should
reference its constants by name, i.e., not their numeric value.
because, by default, the QPushButton draws a native border which completely
overlaps the background-color. For example,
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 30
+ \snippet code/doc_src_stylesheet.qdoc 30
See \l{Qt Style Sheets Examples#Customizing QPushButton}{Customizing QPushButton}
for an example.
because, by default, the QToolButton draws a native border which completely
overlaps the background-color. For example,
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 31
+ \snippet code/doc_src_stylesheet.qdoc 31
See \l{Qt Style Sheets Examples#Customizing QToolButton}{Customizing QToolButton}
for an example.
If you subclass from QWidget, you need to provide a paintEvent for your
custom QWidget as below:
- \snippet doc/src/snippets/code/doc_src_stylesheet.cpp 32
+ \snippet code/doc_src_stylesheet.cpp 32
The above code is a no-operation if there is no stylesheet set.
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 33
+ \snippet code/doc_src_stylesheet.qdoc 33
See also \l{Qt Style Sheets Reference#background-prop}{background} and
\l{#selection-background-color-prop}{selection-background-color}.
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 34
+ \snippet code/doc_src_stylesheet.qdoc 34
Often, it is required to set a fill pattern similar to the styles
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 35
+ \snippet code/doc_src_stylesheet.qdoc 35
See also \l{#background-origin-prop}{background-origin},
\l{#selection-background-color-prop}{selection-background-color},
Examples:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 36
+ \snippet code/doc_src_stylesheet.qdoc 36
\row
\li \c background-image \target background-image-prop
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 37
+ \snippet code/doc_src_stylesheet.qdoc 37
\row
\li \c background-repeat \target background-repeat-prop
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 38
+ \snippet code/doc_src_stylesheet.qdoc 38
\row
\li \c background-position
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 39
+ \snippet code/doc_src_stylesheet.qdoc 39
\row
\li \b{\c background-attachment} \target background-attachment-prop
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 40
+ \snippet code/doc_src_stylesheet.qdoc 40
See also \l{Qt Style Sheets Reference#background-prop}{background}
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 41
+ \snippet code/doc_src_stylesheet.qdoc 41
See also \l{Qt Style Sheets Reference#background-prop}{background},
\l{#background-origin-prop}{background-origin} and \l{The Box Model}.
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 42
+ \snippet code/doc_src_stylesheet.qdoc 42
See also \l{Qt Style Sheets Reference#background-prop}{background} and
\l{The Box Model}.
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 43
+ \snippet code/doc_src_stylesheet.qdoc 43
\row
\li \c border-top
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 44
+ \snippet code/doc_src_stylesheet.qdoc 44
See also \l{Qt Style Sheets Reference#border-style-prop}{border-style},
\l{Qt Style Sheets Reference#border-width-prop}{border-width},
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 45
+ \snippet code/doc_src_stylesheet.qdoc 45
See also \l{Qt Style Sheets Reference#border-width-prop}{border-width} and
\l{The Box Model}.
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 46
+ \snippet code/doc_src_stylesheet.qdoc 46
See also \l{#border-color-prop}{border-color},
\l{Qt Style Sheets Reference#border-style-prop}{border-style},
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 47
+ \snippet code/doc_src_stylesheet.qdoc 47
See also \l{#border-color-prop}{border-color},
\l{#border-radius-prop}{border-radius},
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 48
+ \snippet code/doc_src_stylesheet.qdoc 48
See also \l{Qt Style Sheets Reference#left-prop}{left}, \l{#right-prop}{right}, and
\l{Qt Style Sheets Reference#top-prop}{top}.
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 49
+ \snippet code/doc_src_stylesheet.qdoc 49
\row
\li \b{\c color} \target color-prop
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 50
+ \snippet code/doc_src_stylesheet.qdoc 50
See also \l{Qt Style Sheets Reference#background-prop}{background} and
\l{#selection-color-prop}{selection-color}.
See the \l{Qt Style Sheets Reference#list of icons}{List of Icons}
section for information on how to set icons.
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 51
+ \snippet code/doc_src_stylesheet.qdoc 51
\note Styles defining this property must be applied before the
QDialogButtonBox is created; this means that you must apply the
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 52
+ \snippet code/doc_src_stylesheet.qdoc 52
\endomit
\row
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 53
+ \snippet code/doc_src_stylesheet.qdoc 53
\row
\li \c font-family
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 54
+ \snippet code/doc_src_stylesheet.qdoc 54
\row
\li \c font-size
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 55
+ \snippet code/doc_src_stylesheet.qdoc 55
\row
\li \c font-style
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 56
+ \snippet code/doc_src_stylesheet.qdoc 56
\row
\li \c font-weight
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 57
+ \snippet code/doc_src_stylesheet.qdoc 57
\row
\li \b{\c height} \target height-prop
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 58
+ \snippet code/doc_src_stylesheet.qdoc 58
See also \l{#width-prop}{width}.
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 59
+ \snippet code/doc_src_stylesheet.qdoc 59
\row
\li \b{\c image-position} \target image-position-prop
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 60
+ \snippet code/doc_src_stylesheet.qdoc 60
See also \l{#right-prop}{right}, \l{Qt Style Sheets Reference#top-prop}{top}, and
\l{#bottom-prop}{bottom}.
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 61
+ \snippet code/doc_src_stylesheet.qdoc 61
\row
\li \b{\c margin} \target margin-prop
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 62
+ \snippet code/doc_src_stylesheet.qdoc 62
See also \l{Qt Style Sheets Reference#padding-prop}{padding},
\l{#spacing-prop}{spacing}, and \l{The Box Model}.
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 63
+ \snippet code/doc_src_stylesheet.qdoc 63
See also \l{#max-width-prop}{max-width}.
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 64
+ \snippet code/doc_src_stylesheet.qdoc 64
See also \l{#max-height-prop}{max-height}.
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 65
+ \snippet code/doc_src_stylesheet.qdoc 65
\row
\li \b{\c min-height} \target min-height-prop
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 66
+ \snippet code/doc_src_stylesheet.qdoc 66
See also \l{#min-width-prop}{min-width}.
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 67
+ \snippet code/doc_src_stylesheet.qdoc 67
See also \l{#min-height-prop}{min-height}.
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 68
+ \snippet code/doc_src_stylesheet.qdoc 68
\row
\li \b{\c padding} \target padding-prop
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 69
+ \snippet code/doc_src_stylesheet.qdoc 69
See also \l{#margin-prop}{margin},
\l{#spacing-prop}{spacing}, and \l{The Box Model}.
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 70
+ \snippet code/doc_src_stylesheet.qdoc 70
See also \l{Qt Style Sheets Reference#left-prop}{left}, \l{Qt Style Sheets Reference#top-prop}{top}, and
\l{#bottom-prop}{bottom}.
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 71
+ \snippet code/doc_src_stylesheet.qdoc 71
See also \l{#selection-color-prop}{selection-color} and
\l{Qt Style Sheets Reference#background-prop}{background}.
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 72
+ \snippet code/doc_src_stylesheet.qdoc 72
See also
\l{#selection-background-color-prop}{selection-background-color}
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 73
+ \snippet code/doc_src_stylesheet.qdoc 73
\row
\li \b{\c spacing*} \target spacing-prop
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 74
+ \snippet code/doc_src_stylesheet.qdoc 74
See also \l{Qt Style Sheets Reference#padding-prop}{padding} and
\l{#margin-prop}{margin}.
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 75
+ \snippet code/doc_src_stylesheet.qdoc 75
See also
\l{Qt Style Sheets Reference#subcontrol-position-prop}{subcontrol-position}.
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 76
+ \snippet code/doc_src_stylesheet.qdoc 76
See also
\l{Qt Style Sheets Reference#subcontrol-origin-prop}{subcontrol-origin}.
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 77
+ \snippet code/doc_src_stylesheet.qdoc 77
This property is currently supported only by QPushButton
and QProgressBar.
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 78
+ \snippet code/doc_src_stylesheet.qdoc 78
See also \l{Qt Style Sheets Reference#left-prop}{left}, \l{#right-prop}{right}, and
\l{#bottom-prop}{bottom}.
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 79
+ \snippet code/doc_src_stylesheet.qdoc 79
See also \l{#height-prop}{height}.
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 80
+ \snippet code/doc_src_stylesheet.qdoc 80
\row
\li \b Attachment \target Attachment
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 81
+ \snippet code/doc_src_stylesheet.qdoc 81
\row
\li \b Border \target Border
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 82
+ \snippet code/doc_src_stylesheet.qdoc 82
\row
\li \b{Box Lengths} \target Box Lengths
Examples:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 83
+ \snippet code/doc_src_stylesheet.qdoc 83
\row
\li \b{Brush} \target Brush
Examples:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 84
+ \snippet code/doc_src_stylesheet.qdoc 84
\note The RGB colors allowed are the same as those allowed with
CSS 2.1, as listed
Examples:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 85
+ \snippet code/doc_src_stylesheet.qdoc 85
\row
\li \b{Icon} \target Icon
\li A list of url, QIcon::Mode and QIcon::State.
Example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 86
+ \snippet code/doc_src_stylesheet.qdoc 86
\row
\li \b{Length} \target Length
in the widget's QPalette.
For example,
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 87
+ \snippet code/doc_src_stylesheet.qdoc 87
\row
\li \b{Radius} \target Radius
\l{QLineEdit}s in an application. This could be achieved like
this:
- \snippet doc/src/snippets/code/doc_src_stylesheet.cpp 88
+ \snippet code/doc_src_stylesheet.cpp 88
If we want the property to apply only to the \l{QLineEdit}s that are
children (or grandchildren or grand-grandchildren) of a specific dialog,
we would rather do this:
- \snippet doc/src/snippets/code/doc_src_stylesheet.cpp 89
+ \snippet code/doc_src_stylesheet.cpp 89
If we want the property to apply only to one specific QLineEdit,
we can give it a name using QObject::setObjectName() and use an
ID Selector to refer to it:
- \snippet doc/src/snippets/code/doc_src_stylesheet.cpp 90
+ \snippet code/doc_src_stylesheet.cpp 90
Alternatively, we can set the
\l{Qt Style Sheets Reference#background-prop}{background-color} property directly on the
QLineEdit, omitting the selector:
- \snippet doc/src/snippets/code/doc_src_stylesheet.cpp 91
+ \snippet code/doc_src_stylesheet.cpp 91
To ensure a good contrast, we should also specify a suitable
color for the text:
- \snippet doc/src/snippets/code/doc_src_stylesheet.cpp 92
+ \snippet code/doc_src_stylesheet.cpp 92
It might be a good idea to change the colors used for selected
text as well:
- \snippet doc/src/snippets/code/doc_src_stylesheet.cpp 93
+ \snippet code/doc_src_stylesheet.cpp 93
\section2 Customizing Using Dynamic Properties
turns out this is very easy to implement using Qt Style Sheets.
First, we would use the following application-wide style sheet:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 94
+ \snippet code/doc_src_stylesheet.qdoc 94
This means that every widget whose \c mandatoryField Qt property
is set to true would have a yellow background.
\c mandatoryField property on the fly and set it to true. For
example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.cpp 95
+ \snippet code/doc_src_stylesheet.cpp 95
\section2 Customizing a QPushButton Using the Box Model
First, we are tempted to use this style sheet:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 96
+ \snippet code/doc_src_stylesheet.qdoc 96
However, the result is a boring, flat button with no borders:
Let's improve the situation by specifying a border:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 97
+ \snippet code/doc_src_stylesheet.qdoc 97
\image stylesheet-redbutton2.png A red button with a beige border
enforce a minimum width, round the corners, and specify a larger
font to make the button look nicer:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 98
+ \snippet code/doc_src_stylesheet.qdoc 98
\image stylesheet-redbutton3.png A red button with a round beige border and big, bold text
press it. We can fix this by specifying a slightly different
background color and use a different border style.
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 99
+ \snippet code/doc_src_stylesheet.qdoc 99
\section2 Customizing the QPushButton's Menu Indicator Sub-Control
QPushButton::setMenu()) has a menu indicator. Let's customize
the menu indicator for the red push button:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 100
+ \snippet code/doc_src_stylesheet.qdoc 100
By default, the menu indicator is located at the bottom-right
corner of the padding rectangle. We can change this by specifying
\l{Qt Style Sheets Reference#left-prop}{left} to move the indicator by a few pixels. For
example:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 101
+ \snippet code/doc_src_stylesheet.qdoc 101
This positions the \c myindicator.png to the center right of the
QPushButton's \l{Qt Style Sheets Reference#padding-prop}{padding} rectangle (see
QLineEdit red by setting the following application-wide
stylesheet:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 102
+ \snippet code/doc_src_stylesheet.qdoc 102
However, we would like to give a visual indication that a
QLineEdit is read-only by making it appear gray:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 103
+ \snippet code/doc_src_stylesheet.qdoc 103
At some point, our design team comes with the requirement that
all \l{QLineEdit}s in the registration form (with the
\l{QObject::objectName}{object name} \c registrationDialog) to be
brown:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 104
+ \snippet code/doc_src_stylesheet.qdoc 104
A few UI design meetings later, we decide that all our
\l{QDialog}s should have brown colored \l{QLineEdit}s:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 105
+ \snippet code/doc_src_stylesheet.qdoc 105
Quiz: What happens if we have a read-only QLineEdit in a QDialog?
[Hint: The \l{The Style Sheet Syntax#Conflict Resolution}{Conflict Resolution} section above explains
The background of any QAbstractScrollArea (Item views, QTextEdit
and QTextBrowser) can be set using the background properties. For example,
to set a background-image that scrolls with the scroll bar:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 106
+ \snippet code/doc_src_stylesheet.qdoc 106
If the background-image is to be fixed with the viewport:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 107
+ \snippet code/doc_src_stylesheet.qdoc 107
\section2 Customizing QCheckBox
Styling of a QCheckBox is almost identical to styling a QRadioButton. The
main difference is that a tristate QCheckBox has an indeterminate state.
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 108
+ \snippet code/doc_src_stylesheet.qdoc 108
\section2 Customizing QComboBox
We will look at an example where the drop down button of a QComboBox
appears "merged" with the combo box frame.
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 109
+ \snippet code/doc_src_stylesheet.qdoc 109
The pop-up of the QComboBox is a QAbstractItemView and is styled using
the descendant selector:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 110
+ \snippet code/doc_src_stylesheet.qdoc 110
\section2 Customizing QDockWidget
The title bar and the buttons of a QDockWidget can be customized as
follows:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 111
+ \snippet code/doc_src_stylesheet.qdoc 111
If one desires to move the dock widget buttons to the left, the following
style sheet can be used:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 112
+ \snippet code/doc_src_stylesheet.qdoc 112
\note To customize the separator (resize handle) of a QDockWidget,
use QMainWindow::separator.
A QFrame is styled using the \l{The Box Model}.
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 113
+ \snippet code/doc_src_stylesheet.qdoc 113
\section2 Customizing QGroupBox
Let us look at an example that moves the QGroupBox's title to
the center.
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 114
+ \snippet code/doc_src_stylesheet.qdoc 114
For a checkable QGroupBox, use the \{#indicator-sub}{::indicator} subcontrol
and style it exactly like a QCheckBox (i.e)
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 115
+ \snippet code/doc_src_stylesheet.qdoc 115
\section2 Customizing QHeaderView
QHeaderView is customized as follows:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 116
+ \snippet code/doc_src_stylesheet.qdoc 116
\section2 Customizing QLineEdit
The frame of a QLineEdit is styled using the \l{The Box Model}. To
create a line edit with rounded corners, we can set:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 117
+ \snippet code/doc_src_stylesheet.qdoc 117
The password character of line edits that have QLineEdit::Password
echo mode can be set using:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 118
+ \snippet code/doc_src_stylesheet.qdoc 118
The background of a read only QLineEdit can be modified as below:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 119
+ \snippet code/doc_src_stylesheet.qdoc 119
\section2 Customizing QListView
The background color of alternating rows can be customized using the following
style sheet:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 120
+ \snippet code/doc_src_stylesheet.qdoc 120
To provide a special background when you hover over items, we can use the
\l{item-sub}{::item} subcontrol. For example,
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 121
+ \snippet code/doc_src_stylesheet.qdoc 121
\section2 Customizing QMainWindow
The separator of a QMainWindow can be styled as follows:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 122
+ \snippet code/doc_src_stylesheet.qdoc 122
\section2 Customizing QMenu
Individual items of a QMenu are styled using the 'item' subcontrol as
follows:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 123
+ \snippet code/doc_src_stylesheet.qdoc 123
For a more advanced customization, use a style sheet as follows:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 124
+ \snippet code/doc_src_stylesheet.qdoc 124
\section2 Customizing QMenuBar
QMenuBar is styled as follows:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 125
+ \snippet code/doc_src_stylesheet.qdoc 125
\section2 Customizing QProgressBar
{border} to grey and the \l{stylesheet-reference.html#chunk-sub}{chunk}
to cerulean.
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 126
+ \snippet code/doc_src_stylesheet.qdoc 126
This leaves the \l{stylesheet-reference.html#text-align-prop}
{text-align}, which we customize by positioning the text in the center of
the progress bar.
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 127
+ \snippet code/doc_src_stylesheet.qdoc 127
A \l{stylesheet-reference.html#margin-prop}{margin} can be included to
obtain more visible chunks.
In the screenshot above, we use a
\l{stylesheet-reference.html#margin-prop}{margin} of 0.5 pixels.
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 128
+ \snippet code/doc_src_stylesheet.qdoc 128
\section2 Customizing QPushButton
A QPushButton is styled as follows:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 129
+ \snippet code/doc_src_stylesheet.qdoc 129
For a QPushButton with a menu, use the
\l{Qt Style Sheets Reference#menu-indicator-sub}{::menu-indicator}
subcontrol.
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 130
+ \snippet code/doc_src_stylesheet.qdoc 130
Checkable QPushButton have the \l{Qt Style Sheets Reference#checked-ps}
{:checked} pseudo state set.
\section2 Customizing QRadioButton
The indicator of a QRadioButton can be changed using:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 131
+ \snippet code/doc_src_stylesheet.qdoc 131
\section2 Customizing QScrollBar
The scroll bar above has been styled in aquamarine with a solid grey
border.
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 132
+ \snippet code/doc_src_stylesheet.qdoc 132
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 133
+ \snippet code/doc_src_stylesheet.qdoc 133
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 134
+ \snippet code/doc_src_stylesheet.qdoc 134
The \l{stylesheet-reference.html#left-arrow-sub}{left-arrow} and
\l{stylesheet-reference.html#right-arrow-sub}{right-arrow} have a solid grey
border with a white background. As an alternative, you could also embed the
image of an arrow.
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 135
+ \snippet code/doc_src_stylesheet.qdoc 135
If you want the scroll buttons of the scroll bar to be placed together
(instead of the edges) like on Mac OS X, you can use the following
stylesheet:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 136
+ \snippet code/doc_src_stylesheet.qdoc 136
The scroll bar using the above stylesheet looks like this:
\image stylesheet-scrollbar2.png
To customize a vertical scroll bar use a style sheet similar to the following:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 137
+ \snippet code/doc_src_stylesheet.qdoc 137
\section2 Customizing QSizeGrip
QSizeGrip is usually styled by just setting an image.
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 138
+ \snippet code/doc_src_stylesheet.qdoc 138
\section2 Customizing QSlider
You can style horizontal slider as below:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 139
+ \snippet code/doc_src_stylesheet.qdoc 139
If you want to change the color of the slider parts before and after the handle, you can use the add-page
and sub-page subcontrols. For example, for a vertical slider:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 140
+ \snippet code/doc_src_stylesheet.qdoc 140
\section2 Customizing QSpinBox
QSpinBox can be completely customized as below (the style sheet has commentary inline):
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 141
+ \snippet code/doc_src_stylesheet.qdoc 141
\section2 Customizing QSplitter
The grip or the handle is customized using the
\l{Qt Style Sheets Reference#handle-sub}{::handle} subcontrol.
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 142
+ \snippet code/doc_src_stylesheet.qdoc 142
\section2 Customizing QStatusBar
We can provide a background for the status bar and a border for items
inside the status bar as follows:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 143
+ \snippet code/doc_src_stylesheet.qdoc 143
Note that widgets that have been added to the QStatusBar can be styled
using the descendant declaration (i.e)
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 144
+ \snippet code/doc_src_stylesheet.qdoc 144
\section2 Customizing QTabWidget and QTabBar
For the screenshot above, we need a stylesheet as follows:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 145
+ \snippet code/doc_src_stylesheet.qdoc 145
Often we require the tabs to overlap to look like below:
\image tabWidget-stylesheet2.png
\l{http://www.communitymx.com/content/article.cfm?cid=B0029}
{negative margins}. The resulting stylesheet looks like this:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 146
+ \snippet code/doc_src_stylesheet.qdoc 146
To move the tab bar to the center (as below), we require the following stylesheet:
\image tabWidget-stylesheet3.png
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 147
+ \snippet code/doc_src_stylesheet.qdoc 147
The tear indicator and the scroll buttons can be further customized as follows:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 148
+ \snippet code/doc_src_stylesheet.qdoc 148
Since Qt 4.6 the close button can be customized as follow:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 159
+ \snippet code/doc_src_stylesheet.qdoc 159
\section2 Customizing QTableView
\l{stylesheet-reference.html#selection-background-color-prop}
{selection-background-color} property and the syntax required is:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 149
+ \snippet code/doc_src_stylesheet.qdoc 149
The corner widget can be customized using the following style sheet
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 150
+ \snippet code/doc_src_stylesheet.qdoc 150
\section2 Customizing QToolBar
The background and the handle of a QToolBar is customized as below:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 151
+ \snippet code/doc_src_stylesheet.qdoc 151
\section2 Customizing QToolBox
The tabs of the QToolBox are customized using the 'tab' subcontrol.
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 152
+ \snippet code/doc_src_stylesheet.qdoc 152
\section2 Customizing QToolButton
QToolButton::MenuButtonPopup. In this case, we style it as follows:
\endlist
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 153
+ \snippet code/doc_src_stylesheet.qdoc 153
\section2 Customizing QToolTip
that support it, the opacity property may be set to adjust the opacity.
For example,
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 154
+ \snippet code/doc_src_stylesheet.qdoc 154
\section2 Customizing QTreeView
The background color of alternating rows can be customized using the following
style sheet:
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 155
+ \snippet code/doc_src_stylesheet.qdoc 155
To provide a special background when you hover over items, we can use the
\l{item-sub}{::item} subcontrol. For example,
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 156
+ \snippet code/doc_src_stylesheet.qdoc 156
The branches of a QTreeView are styled using the
\l{Qt Style Sheets Reference#branch-sub}{::branch} subcontrol. The
following stylesheet color codes the various states when drawing
a branch.
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 157
+ \snippet code/doc_src_stylesheet.qdoc 157
Colorful, though it is, a more useful example can be made using the
following images:
\li branch-open.png
\endtable
- \snippet doc/src/snippets/code/doc_src_stylesheet.qdoc 158
+ \snippet code/doc_src_stylesheet.qdoc 158
The resulting tree view looks like this:
Consider the following snippet:
- \snippet doc/src/snippets/stylesheet/common-mistakes.cpp 1
+ \snippet stylesheet/common-mistakes.cpp 1
This will produce a button looking like this:
For example:
- \snippet doc/src/snippets/code/src_gui_effects_qgraphicseffect.cpp 0
+ \snippet code/src_gui_effects_qgraphicseffect.cpp 0
\sa QGraphicsEffect::draw()
*/
For example:
- \snippet doc/src/snippets/code/src_gui_effects_qgraphicseffect.cpp 1
+ \snippet code/src_gui_effects_qgraphicseffect.cpp 1
This function should not be called explicitly by the user, since it is
meant for reimplementation purposes only.
For example:
- \snippet doc/src/snippets/code/src_gui_effects_qgraphicseffect.cpp 2
+ \snippet code/src_gui_effects_qgraphicseffect.cpp 2
There is no opacity mask by default.
\endomit
Example:
- \snippet doc/src/snippets/code/src_gui_image_qpixmapfilter.cpp 1
+ \snippet code/src_gui_image_qpixmapfilter.cpp 1
\sa {Pixmap Filters Example}, QPixmapColorizeFilter, QPixmapDropShadowFilter
chosen color. The alpha-channel is not changed.
Example:
- \snippet doc/src/snippets/code/src_gui_image_qpixmapfilter.cpp 0
+ \snippet code/src_gui_image_qpixmapfilter.cpp 0
\sa QPainter::CompositionMode
radius of 1 at an offset of 8 pixels towards the lower right.
Example:
- \snippet doc/src/snippets/code/src_gui_image_qpixmapfilter.cpp 2
+ \snippet code/src_gui_image_qpixmapfilter.cpp 2
\sa QPixmapColorizeFilter, QPixmapConvolutionFilter
Anchors are always set up between edges of an item, where the "center" is also considered to
be an edge. Consider the following example:
- \snippet examples/graphicsview/simpleanchorlayout/main.cpp adding anchors
+ \snippet graphicsview/simpleanchorlayout/main.cpp adding anchors
Here, the right edge of item \c a is anchored to the left edge of item \c b and the bottom
edge of item \c a is anchored to the top edge of item \c b, with the result that
above. Here, we see how a widget can be anchored to the top-left corner of the enclosing
layout:
- \snippet examples/graphicsview/simpleanchorlayout/main.cpp adding a corner anchor
+ \snippet graphicsview/simpleanchorlayout/main.cpp adding a corner anchor
In cases where anchors are used to match the widths or heights of widgets, it is
convenient to use the addAnchors() function. As with the other functions for specifying
This is a convenience function, since anchoring corners can be expressed as anchoring
two edges. For instance:
- \snippet examples/graphicsview/simpleanchorlayout/main.cpp adding a corner anchor in two steps
+ \snippet graphicsview/simpleanchorlayout/main.cpp adding a corner anchor in two steps
This can also be achieved with the following line of code:
- \snippet examples/graphicsview/simpleanchorlayout/main.cpp adding a corner anchor
+ \snippet graphicsview/simpleanchorlayout/main.cpp adding a corner anchor
If there is already an anchor between the edge pairs, it will be replaced by the anchors that
this function specifies.
For example, the following example anchors the left and right edges of two items
to match their widths:
- \snippet examples/graphicsview/simpleanchorlayout/main.cpp adding anchors to match sizes in two steps
+ \snippet graphicsview/simpleanchorlayout/main.cpp adding anchors to match sizes in two steps
This can also be achieved using the following line of code:
- \snippet examples/graphicsview/simpleanchorlayout/main.cpp adding anchors to match sizes
+ \snippet graphicsview/simpleanchorlayout/main.cpp adding anchors to match sizes
\sa addAnchor(), addCornerAnchors()
*/
QGraphicsWidget::setLayout(). QGraphicsGridLayout automatically computes
the dimensions of the grid as you add items.
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsgridlayout.cpp 0
+ \snippet code/src_gui_graphicsview_qgraphicsgridlayout.cpp 0
The layout takes ownership of the items. In some cases when the layout
item also inherits from QGraphicsItem (such as QGraphicsWidget) there will be a
by the item, and paint(), which implements the actual painting. For
example:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 0
+ \snippet code/src_gui_graphicsview_qgraphicsitem.cpp 0
The boundingRect() function has many different purposes.
QGraphicsScene bases its item index on boundingRect(), and
classes in Qt are associated with a unique value for Type,
e.g. the value returned by QGraphicsPathItem::type() is 2.
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 18
+ \snippet code/src_gui_graphicsview_qgraphicsitem.cpp 18
*/
/*!
used in conjunction with a reimplementation of QGraphicsItem::type()
and declaring a Type enum value. Example:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 1
+ \snippet code/src_gui_graphicsview_qgraphicsitem.cpp 1
\note UserType = 65536
*/
An editor item might want to use an I-beam cursor:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 2
+ \snippet code/src_gui_graphicsview_qgraphicsitem.cpp 2
If no cursor has been set, the cursor of the item beneath is used.
An editor item might want to use an I-beam cursor:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 3
+ \snippet code/src_gui_graphicsview_qgraphicsitem.cpp 3
If no cursor has been set, the cursor of the item beneath is used.
Example:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 4
+ \snippet code/src_gui_graphicsview_qgraphicsitem.cpp 4
Unlike transform(), which returns only an item's local transformation, this
function includes the item's (and any parents') position, and all the transfomation properties.
Example:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 5
+ \snippet code/src_gui_graphicsview_qgraphicsitem.cpp 5
This function is the same as combining this item's scene transform with
the view's viewport transform, but it also understands the
Example:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 6
+ \snippet code/src_gui_graphicsview_qgraphicsitem.cpp 6
\sa setTransform(), transform(), scale(), shear(), translate()
*/
Example:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 7
+ \snippet code/src_gui_graphicsview_qgraphicsitem.cpp 7
\sa setTransform(), transform()
*/
Example:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 8
+ \snippet code/src_gui_graphicsview_qgraphicsitem.cpp 8
\sa boundingRegion(), shape(), contains(), {The Graphics View Coordinate
System}, prepareGeometryChange()
may choose to return an elliptic shape for better collision detection. For
example:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 9
+ \snippet code/src_gui_graphicsview_qgraphicsitem.cpp 9
The outline of a shape can vary depending on the width and style of the
pen used when drawing. If you want to include this outline in the item's
provided, it points to the widget that is being painted on; otherwise, it
is 0. For cached painting, \a widget is always 0.
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 10
+ \snippet code/src_gui_graphicsview_qgraphicsitem.cpp 10
The painter's pen is 0-width by default, and its pen is initialized to the
QPalette::Text brush from the paint device's palette. The brush is
by other items, you can map the \a rect to viewport coordinates and scroll the
viewport.
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 19
+ \snippet code/src_gui_graphicsview_qgraphicsitem.cpp 19
\sa boundingRect()
*/
Custom item data is useful for storing arbitrary properties in any
item. Example:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 11
+ \snippet code/src_gui_graphicsview_qgraphicsitem.cpp 11
Qt does not use this feature for storing data; it is provided solely
for the convenience of the user.
For example:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp QGraphicsItem type
+ \snippet code/src_gui_graphicsview_qgraphicsitem.cpp QGraphicsItem type
\sa UserType
*/
To filter another item's events, install this item as an event filter
for the other item. Example:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 12
+ \snippet code/src_gui_graphicsview_qgraphicsitem.cpp 12
An item can only filter events for other items in the same
scene. Also, an item cannot filter its own events; instead, you
It's common to open a QMenu in response to receiving a context menu
event. Example:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 13
+ \snippet code/src_gui_graphicsview_qgraphicsitem.cpp 13
The default implementation ignores the event.
A common implementation of dragEnterEvent accepts or ignores \a event
depending on the associated mime data in \a event. Example:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 14
+ \snippet code/src_gui_graphicsview_qgraphicsitem.cpp 14
Items do not receive drag and drop events by default; to enable this
feature, call \c setAcceptDrops(true).
Example:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 15
+ \snippet code/src_gui_graphicsview_qgraphicsitem.cpp 15
The default implementation does nothing, and returns \a value.
Example:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 16
+ \snippet code/src_gui_graphicsview_qgraphicsitem.cpp 16
\sa boundingRect()
*/
/*!
\since 4.5
- If \a b is true, the \gui Tab key will cause the widget to change focus;
+ If \a b is true, the \uicontrol Tab key will cause the widget to change focus;
otherwise, the tab key will insert a tab into the document.
In some occasions text edits should not allow the user to input tabulators
- or change indentation using the \gui Tab key, as this breaks the focus
+ or change indentation using the \uicontrol Tab key, as this breaks the focus
chain. The default is false.
\sa tabChangesFocus(), ItemIsFocusable, textInteractionFlags()
/*!
\since 4.5
- Returns true if the \gui Tab key will cause the widget to change focus;
+ Returns true if the \uicontrol Tab key will cause the widget to change focus;
otherwise, false is returned.
By default, this behavior is disabled, and this function will return false.
QGraphicsScene::destroyItemGroup(), or you can manually remove all
items from the group by calling removeFromGroup().
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 17
+ \snippet code/src_gui_graphicsview_qgraphicsitem.cpp 17
The operation of adding and removing items preserves the items'
scene-relative position and transformation, as opposed to calling
An example animation with a timeline follows:
- \snippet doc/src/snippets/timeline/main.cpp 0
+ \snippet timeline/main.cpp 0
Note that steps lie between 0.0 and 1.0. It may be necessary to use
\l{QTimeLine::}{setUpdateInterval()}. The default update interval
and finally assign the layout to a widget by calling
QGraphicsWidget::setLayout().
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicslinearlayout.cpp 0
+ \snippet code/src_gui_graphicsview_qgraphicslinearlayout.cpp 0
You can add widgets, layouts, stretches (addStretch(), insertStretch() or
setStretchFactor()), and spacings (setItemSpacing()) to a linear
Example:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsproxywidget.cpp 0
+ \snippet code/src_gui_graphicsview_qgraphicsproxywidget.cpp 0
QGraphicsProxyWidget takes care of automatically embedding popup children
of embedded widgets through creating a child proxy for each popup. This
For example, in the code snippet below, we embed a group box into the proxy:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsproxywidget.cpp 1
+ \snippet code/src_gui_graphicsview_qgraphicsproxywidget.cpp 1
The image below is the output obtained with its contents margin and
contents rect labeled.
Example:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsproxywidget.cpp 2
+ \snippet code/src_gui_graphicsview_qgraphicsproxywidget.cpp 2
QGraphicsProxyWidget maintains symmetry for the following states:
Example:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsscene.cpp 0
+ \snippet code/src_gui_graphicsview_qgraphicsscene.cpp 0
Note that QGraphicsScene has no visual appearance of its own; it only
manages the items. You need to create a QGraphicsView widget to visualize
device, such as a QImage (e.g., to take a screenshot), or for printing
with QPrinter. For example:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsscene.cpp 1
+ \snippet code/src_gui_graphicsview_qgraphicsscene.cpp 1
If \a source is a null rect, this function will use sceneRect() to
determine what to render. If \a target is a null rect, the dimensions of \a
granularity of the scene's partitioning. The size of each scene segment is
determined by the following algorithm:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsscene.cpp 2
+ \snippet code/src_gui_graphicsview_qgraphicsscene.cpp 2
The BSP tree has an optimal size when each segment contains between 0 and
10 items.
Example:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsscene.cpp 3
+ \snippet code/src_gui_graphicsview_qgraphicsscene.cpp 3
QGraphicsScene::render() calls drawBackground() to draw the scene
background. For more detailed control over how the background is drawn,
Example:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsscene.cpp 4
+ \snippet code/src_gui_graphicsview_qgraphicsscene.cpp 4
QGraphicsScene::render() calls drawForeground() to draw the scene
foreground. For more detailed control over how the foreground is
Example:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsscene.cpp 5
+ \snippet code/src_gui_graphicsview_qgraphicsscene.cpp 5
Note that QGraphicsView currently supports background caching only (see
QGraphicsView::CacheBackground). This function is equivalent to calling
Example:
- \snippet doc/src/snippets/graphicssceneadditemsnippet.cpp 0
+ \snippet graphicssceneadditemsnippet.cpp 0
Since Qt 4.6, this function is not called anymore unless
the QGraphicsView::IndirectPainting flag is given as an Optimization
Sets the proposed action as accepted, i.e, the drop action
is set to the proposed action. This is equal to:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicssceneevent.cpp 0
+ \snippet code/src_gui_graphicsview_qgraphicssceneevent.cpp 0
When using this function, one should not call \c accept().
center of the scene and display any items that are visible at this
point. For example:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsview.cpp 0
+ \snippet code/src_gui_graphicsview_qgraphicsview.cpp 0
You can explicitly scroll to any position on the scene by using the
scroll bars, or by calling centerOn(). By passing a point to centerOn(),
Example:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsview.cpp 1
+ \snippet code/src_gui_graphicsview_qgraphicsview.cpp 1
*/
QPainter::RenderHints QGraphicsView::renderHints() const
{
especially with a transformed view. The CacheBackground flag enables
caching of the view's background. For example:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsview.cpp 2
+ \snippet code/src_gui_graphicsview_qgraphicsview.cpp 2
The cache is invalidated every time the view is transformed. However, when
scrolling, only partial invalidation is required.
Example:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsview.cpp 3
+ \snippet code/src_gui_graphicsview_qgraphicsview.cpp 3
To simplify interation with items using a transformed view, QGraphicsView
provides mapTo... and mapFrom... functions that can translate between
onto a paint device, such as a QImage (e.g., to take a screenshot), or for
printing to QPrinter. For example:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsview.cpp 4
+ \snippet code/src_gui_graphicsview_qgraphicsview.cpp 4
If \a source is a null rect, this function will use viewport()->rect() to
determine what to draw. If \a target is a null rect, the full dimensions
a subclass in QGraphicsView. \a pos is in untransformed viewport
coordinates, just like QMouseEvent::pos().
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsview.cpp 5
+ \snippet code/src_gui_graphicsview_qgraphicsview.cpp 5
\sa QGraphicsScene::items(), {QGraphicsItem#Sorting}{Sorting}
*/
Example:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsview.cpp 6
+ \snippet code/src_gui_graphicsview_qgraphicsview.cpp 6
\sa items(), {QGraphicsItem#Sorting}{Sorting}
*/
Example:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsview.cpp 7
+ \snippet code/src_gui_graphicsview_qgraphicsview.cpp 7
To simplify interation with items using a transformed view, QGraphicsView
provides mapTo... and mapFrom... functions that can translate between
For example:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicswidget.cpp 0
+ \snippet code/src_gui_graphicsview_qgraphicswidget.cpp 0
\sa QStyleOption::initFrom()
*/
Note that since the tab order of the \a second widget is changed, you
should order a chain like this:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicswidget.cpp 1
+ \snippet code/src_gui_graphicsview_qgraphicswidget.cpp 1
\e not like this:
- \snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicswidget.cpp 2
+ \snippet code/src_gui_graphicsview_qgraphicswidget.cpp 2
If \a first is 0, this indicates that \a second should be the first widget
to receive input focus should the scene gain Tab focus (i.e., the user
We create the \c WidgetDelegate class, which inherits from
QStyledItemDelegate. We do the drawing in the paint() function:
- \snippet doc/src/snippets/widgetdelegate.cpp 0
+ \snippet widgetdelegate.cpp 0
Notice that we use a QStyleOptionProgressBar and initialize its
members. We can then use the current QStyle to draw it.
setVerticalScrollMode(). To set the range of the scroll bars, you
can, for example, reimplement the view's resizeEvent() function:
- \snippet doc/src/snippets/code/src_gui_itemviews_qabstractitemview.cpp 0
+ \snippet code/src_gui_itemviews_qabstractitemview.cpp 0
Note that the range is not updated until the widget is shown.
views. We recommend that you delete the old selection model if it is no
longer required. This is done with the following code:
- \snippet doc/src/snippets/code/src_gui_itemviews_qabstractitemview.cpp 2
+ \snippet code/src_gui_itemviews_qabstractitemview.cpp 2
If both the old model and the old selection model do not have parents, or
if their parents are long-lived objects, it may be preferable to call their
deleted. For example, in the code snippet below, the QLineEdit object will
be deleted.
- \snippet doc/src/snippets/code/src_gui_itemviews_qabstractitemview.cpp 1
+ \snippet code/src_gui_itemviews_qabstractitemview.cpp 1
This function should only be used to display static content within the
visible area corresponding to an item of data. If you want to display
The following code will map the columns of the model to widgets called \c mySpinBox,
\c myLineEdit and \c{myCountryChooser}:
- \snippet doc/src/snippets/code/src_gui_itemviews_qdatawidgetmapper.cpp 0
+ \snippet code/src_gui_itemviews_qdatawidgetmapper.cpp 0
After the call to toFirst(), \c mySpinBox displays the value \c{1}, \c myLineEdit
displays \c{Qt Norway} and \c myCountryChooser displays \c{Oslo}. The
is mapped to the QLineEdit \c nameLineEdit, and the second is
mapped to the QSpinBox \c{ageSpinBox}:
- \snippet doc/src/snippets/code/src_gui_itemviews_qdatawidgetmapper.cpp 1
+ \snippet code/src_gui_itemviews_qdatawidgetmapper.cpp 1
\b{Notes:}
\list
with new data whenever the selection of a QTableView named
\c myTableView changes:
- \snippet doc/src/snippets/code/src_gui_itemviews_qdatawidgetmapper.cpp 2
+ \snippet code/src_gui_itemviews_qdatawidgetmapper.cpp 2
\sa currentIndex()
*/
For example, a selected item may need to be displayed differently to
unselected items, as shown in the following code:
- \snippet examples/itemviews/pixelator/pixeldelegate.cpp 2
+ \snippet itemviews/pixelator/pixeldelegate.cpp 2
\dots
After painting, you should ensure that the painter is returned to its
key press events are handled by default:
\list
- \li \gui Tab
- \li \gui Backtab
- \li \gui Enter
- \li \gui Return
- \li \gui Esc
+ \li \uicontrol Tab
+ \li \uicontrol Backtab
+ \li \uicontrol Enter
+ \li \uicontrol Return
+ \li \uicontrol Esc
\endlist
- In the case of \gui Tab, \gui Backtab, \gui Enter and \gui Return
+ In the case of \uicontrol Tab, \uicontrol Backtab, \uicontrol Enter and \uicontrol Return
key press events, the \a editor's data is comitted to the model
- and the editor is closed. If the \a event is a \gui Tab key press
+ and the editor is closed. If the \a event is a \uicontrol Tab key press
the view will open an editor on the next item in the
- view. Likewise, if the \a event is a \gui Backtab key press the
+ view. Likewise, if the \a event is a \uicontrol Backtab key press the
view will open an editor on the \e previous item in the view.
- If the event is a \gui Esc key press event, the \a editor is
+ If the event is a \uicontrol Esc key press event, the \a editor is
closed \e without committing its data.
\sa commitData(), closeEditor()
editing data. A property is set as the user property with the USER
keyword:
- \snippet doc/src/snippets/code/src_gui_itemviews_qitemeditorfactory.cpp 0
+ \snippet code/src_gui_itemviews_qitemeditorfactory.cpp 0
If the editor does not provide a user property, it must return the
name of the property from valuePropertyName(); delegates will then
This way, it is not necessary to subclass
QItemEditorCreatorBase.
- \snippet doc/src/snippets/code/src_gui_itemviews_qitemeditorfactory.cpp 1
+ \snippet code/src_gui_itemviews_qitemeditorfactory.cpp 1
The constructor takes the name of the property that contains the
editing data. QItemDelegate can then access the property by name
Example:
- \snippet doc/src/snippets/code/src_gui_itemviews_qitemeditorfactory.cpp 2
+ \snippet code/src_gui_itemviews_qitemeditorfactory.cpp 2
Setting the \c editorFactory created above in an item delegate via
QItemDelegate::setItemEditorFactory() makes sure that all values of type
System}{meta-object system}). You set the user property with
the USER keyword:
- \snippet doc/src/snippets/code/src_gui_itemviews_qitemeditorfactory.cpp 3
+ \snippet code/src_gui_itemviews_qitemeditorfactory.cpp 3
\sa QItemEditorCreatorBase, QItemEditorCreator,
QItemEditorFactory, QItemDelegate, {Color Editor Factory Example}
List items can be inserted automatically into a list, when they are
constructed, by specifying the list widget:
- \snippet doc/src/snippets/qlistwidget-using/mainwindow.cpp 2
+ \snippet qlistwidget-using/mainwindow.cpp 2
Alternatively, list items can also be created without a parent widget, and
later inserted into a list using QListWidget::insertItem().
List widgets are constructed in the same way as other widgets:
- \snippet doc/src/snippets/qlistwidget-using/mainwindow.cpp 0
+ \snippet qlistwidget-using/mainwindow.cpp 0
The selectionMode() of a list widget determines how many of the items in
the list can be selected at the same time, and whether complex selections
parent widget and added to the list later. If a list widget already exists
when the items are constructed, the first method is easier to use:
- \snippet doc/src/snippets/qlistwidget-using/mainwindow.cpp 1
+ \snippet qlistwidget-using/mainwindow.cpp 1
If you need to insert a new item into the list at a particular position,
then it should be constructed without a parent widget. The insertItem()
function should then be used to place it within the list. The list widget
will take ownership of the item.
- \snippet doc/src/snippets/qlistwidget-using/mainwindow.cpp 6
- \snippet doc/src/snippets/qlistwidget-using/mainwindow.cpp 7
+ \snippet qlistwidget-using/mainwindow.cpp 6
+ \snippet qlistwidget-using/mainwindow.cpp 7
For multiple items, insertItems() can be used instead. The number of items
in the list is found with the count() function. To remove items from the
This signal is emitted when the \a item is activated. The \a item is
activated when the user clicks or double clicks on it, depending on the
system configuration. It is also activated when the user presses the
- activation key (on Windows and X11 this is the \gui Return key, on Mac OS
+ activation key (on Windows and X11 this is the \uicontrol Return key, on Mac OS
X it is \key{Ctrl+0}).
*/
An example usage of QStandardItemModel to create a table:
- \snippet doc/src/snippets/code/src_gui_itemviews_qstandarditemmodel.cpp 0
+ \snippet code/src_gui_itemviews_qstandarditemmodel.cpp 0
An example usage of QStandardItemModel to create a tree:
- \snippet doc/src/snippets/code/src_gui_itemviews_qstandarditemmodel.cpp 1
+ \snippet code/src_gui_itemviews_qstandarditemmodel.cpp 1
After setting the model on a view, you typically want to react to user
actions, such as an item being clicked. Since a QAbstractItemView provides
a QAbstractItemView signal, such as QAbstractItemView::clicked(). First
you connect the view's signal to a slot in your class:
- \snippet doc/src/snippets/code/src_gui_itemviews_qstandarditemmodel.cpp 2
+ \snippet code/src_gui_itemviews_qstandarditemmodel.cpp 2
When you receive the signal, you call itemFromIndex() on the given model
index to get a pointer to the item:
- \snippet doc/src/snippets/code/src_gui_itemviews_qstandarditemmodel.cpp 3
+ \snippet code/src_gui_itemviews_qstandarditemmodel.cpp 3
Conversely, you must obtain the QModelIndex of an item when you want to
invoke a model/view function that takes an index as argument. You can
obtain the index either by using the model's indexFromItem() function, or,
equivalently, by calling QStandardItem::index():
- \snippet doc/src/snippets/code/src_gui_itemviews_qstandarditemmodel.cpp 4
+ \snippet code/src_gui_itemviews_qstandarditemmodel.cpp 4
You are, of course, not required to use the item-based approach; you could
instead rely entirely on the QAbstractItemModel interface when working with
key press events are handled by default:
\list
- \li \gui Tab
- \li \gui Backtab
- \li \gui Enter
- \li \gui Return
- \li \gui Esc
+ \li \uicontrol Tab
+ \li \uicontrol Backtab
+ \li \uicontrol Enter
+ \li \uicontrol Return
+ \li \uicontrol Esc
\endlist
- In the case of \gui Tab, \gui Backtab, \gui Enter and \gui Return
+ In the case of \uicontrol Tab, \uicontrol Backtab, \uicontrol Enter and \uicontrol Return
key press events, the \a editor's data is comitted to the model
- and the editor is closed. If the \a event is a \gui Tab key press
+ and the editor is closed. If the \a event is a \uicontrol Tab key press
the view will open an editor on the next item in the
- view. Likewise, if the \a event is a \gui Backtab key press the
+ view. Likewise, if the \a event is a \uicontrol Backtab key press the
view will open an editor on the \e previous item in the view.
- If the event is a \gui Esc key press event, the \a editor is
+ If the event is a \uicontrol Esc key press event, the \a editor is
closed \e without committing its data.
\sa commitData(), closeEditor()
Top-level items are constructed without a parent then inserted at the
position specified by a pair of row and column numbers:
- \snippet doc/src/snippets/qtablewidget-using/mainwindow.cpp 3
+ \snippet qtablewidget-using/mainwindow.cpp 3
Each item can have its own background brush which is set with
the setBackground() function. The current background brush can be
Table widgets can be constructed with the required numbers of rows and
columns:
- \snippet doc/src/snippets/qtablewidget-using/mainwindow.cpp 0
+ \snippet qtablewidget-using/mainwindow.cpp 0
Alternatively, tables can be constructed without a given size and resized
later:
- \snippet doc/src/snippets/qtablewidget-resizing/mainwindow.cpp 0
- \snippet doc/src/snippets/qtablewidget-resizing/mainwindow.cpp 1
+ \snippet qtablewidget-resizing/mainwindow.cpp 0
+ \snippet qtablewidget-resizing/mainwindow.cpp 1
Items are created ouside the table (with no parent widget) and inserted
into the table with setItem():
- \snippet doc/src/snippets/qtablewidget-resizing/mainwindow.cpp 2
+ \snippet qtablewidget-resizing/mainwindow.cpp 2
If you want to enable sorting in your table widget, do so after you
have populated it with items, otherwise sorting may interfere with
construct a table item with an icon and aligned text, and use it as the
header for a particular column:
- \snippet doc/src/snippets/qtablewidget-using/mainwindow.cpp 2
+ \snippet qtablewidget-using/mainwindow.cpp 2
The number of rows in the table can be found with rowCount(), and the
number of columns with columnCount(). The table can be cleared with the
deleted. For example, in the code snippet below, the QLineEdit object will
be deleted.
- \snippet doc/src/snippets/code/src_gui_itemviews_qtablewidget.cpp 0
+ \snippet code/src_gui_itemviews_qtablewidget.cpp 0
\sa cellWidget()
*/
model. In the following example, the contents of a directory are
supplied by a QFileSystemModel and displayed as a tree:
- \snippet doc/src/snippets/shareddirmodel/main.cpp 3
- \snippet doc/src/snippets/shareddirmodel/main.cpp 6
+ \snippet shareddirmodel/main.cpp 3
+ \snippet shareddirmodel/main.cpp 6
The model/view architecture ensures that the contents of the tree view
are updated as the model changes.
to represent cities of the world, and adds a entry for Oslo as a child
item:
- \snippet doc/src/snippets/qtreewidget-using/mainwindow.cpp 3
+ \snippet qtreewidget-using/mainwindow.cpp 3
Items can be added in a particular order by specifying the item they
follow when they are constructed:
- \snippet doc/src/snippets/qtreewidget-using/mainwindow.cpp 5
+ \snippet qtreewidget-using/mainwindow.cpp 5
Each column in an item can have its own background brush which is set with
the setBackground() function. The current background brush can be
In its simplest form, a tree widget can be constructed in the following way:
- \snippet doc/src/snippets/code/src_gui_itemviews_qtreewidget.cpp 0
+ \snippet code/src_gui_itemviews_qtreewidget.cpp 0
Before items can be added to the tree widget, the number of columns must
be set with setColumnCount(). This allows each item to have one or more
For example, the following code examples each item in a tree, checking the
text in the first column against a user-specified search string:
- \snippet doc/src/snippets/qtreewidgetitemiterator-using/mainwindow.cpp 0
+ \snippet qtreewidgetitemiterator-using/mainwindow.cpp 0
It is also possible to filter out certain types of node by passing certain
\l{IteratorFlag}{flags} to the constructor of QTreeWidgetItemIterator.
menu and toolbar, then connected to the slot which will perform
the action. For example:
- \snippet examples/mainwindows/application/mainwindow.cpp 19
+ \snippet mainwindows/application/mainwindow.cpp 19
\codeline
- \snippet examples/mainwindows/application/mainwindow.cpp 28
- \snippet examples/mainwindows/application/mainwindow.cpp 31
+ \snippet mainwindows/application/mainwindow.cpp 28
+ \snippet mainwindows/application/mainwindow.cpp 31
We recommend that actions are created as children of the window
they are used in. In most cases actions will be children of
which indicates that they are unavailable. For example, they might
be displayed using only shades of gray.
- \gui{What's This?} help on disabled actions is still available, provided
+ \uicontrol{What's This?} help on disabled actions is still available, provided
that the QAction::whatsThis property is set.
An action will be disabled when all widgets to which it is added
the presence (or abscence) of the attribute.
For example:
- \snippet doc/src/snippets/code/src_gui_kernel_qaction.cpp 0
+ \snippet code/src_gui_kernel_qaction.cpp 0
\sa QAction::icon QApplication::setAttribute()
*/
\inmodule QtWidgets
In some situations it is useful to group QAction objects together.
- For example, if you have a \gui{Left Align} action, a \gui{Right
- Align} action, a \gui{Justify} action, and a \gui{Center} action,
+ For example, if you have a \uicontrol{Left Align} action, a \uicontrol{Right
+ Align} action, a \uicontrol{Justify} action, and a \uicontrol{Center} action,
only one of these actions should be active at any one time. One
simple way of achieving this is to group the actions together in
an action group.
Here's a example (from the \l{mainwindows/menus}{Menus} example):
- \snippet examples/mainwindows/menus/mainwindow.cpp 6
+ \snippet mainwindows/menus/mainwindow.cpp 6
Here we create a new action group. Since the action group is
exclusive by default, only one of the actions in the group is
\obsolete
- \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 0
+ \snippet code/src_gui_kernel_qapplication.cpp 0
*/
QApplication::QApplication(int &argc, char **argv, bool GUIenabled , int _internal)
still the parent of the application object.
Example usage:
- \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 1
+ \snippet code/src_gui_kernel_qapplication.cpp 1
When switching application styles, the color palette is set back to the
initial colors or the system defaults. This is necessary since certain
Example:
- \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 2
+ \snippet code/src_gui_kernel_qapplication.cpp 2
\sa colorSpec()
*/
Example:
- \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 3
+ \snippet code/src_gui_kernel_qapplication.cpp 3
By default, this property contains a QSize object with zero width and height.
*/
Example:
- \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 4
+ \snippet code/src_gui_kernel_qapplication.cpp 4
\sa allWidgets(), QWidget::isWindow(), QWidget::isHidden()
*/
\note Some of the widgets may be hidden.
Example:
- \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 5
+ \snippet code/src_gui_kernel_qapplication.cpp 5
\sa topLevelWidgets(), QWidget::isVisible()
*/
Closes all top-level windows.
This function is particularly useful for applications with many top-level
- windows. It could, for example, be connected to a \gui{Exit} entry in the
- \gui{File} menu:
+ windows. It could, for example, be connected to a \uicontrol{Exit} entry in the
+ \uicontrol{File} menu:
- \snippet examples/mainwindows/mdi/mainwindow.cpp 0
+ \snippet mainwindows/mdi/mainwindow.cpp 0
The windows are closed in random order, until one window does not accept
the close event. The application quits when the last window was
Displays a simple message box about Qt. The message includes the version
number of Qt being used by the application.
- This is useful for inclusion in the \gui Help menu of an application, as
+ This is useful for inclusion in the \uicontrol Help menu of an application, as
shown in the \l{mainwindows/menus}{Menus} example.
This function is a convenience slot for QMessageBox::aboutQt().
and the current position (e.g. in the mouse move event) is \c currentPos,
you can find out if a drag should be started with code like this:
- \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 7
+ \snippet code/src_gui_kernel_qapplication.cpp 7
Qt uses this value internally, e.g. in QFileDialog.
Here's an example of how an application's QApplication::commitData() might
be implemented:
- \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 8
+ \snippet code/src_gui_kernel_qapplication.cpp 8
If an error occurred within the application while saving its data, you may
want to try allowsErrorInteraction() instead.
If the session manager is capable of restoring sessions it will execute
\a command in order to restore the application. The command defaults to
- \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 9
+ \snippet code/src_gui_kernel_qapplication.cpp 9
The \c -session option is mandatory; otherwise QApplication cannot tell
whether it has been restored or what the current session identifier is.
To iterate over the list, you can use the \l foreach pseudo-keyword:
- \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 10
+ \snippet code/src_gui_kernel_qapplication.cpp 10
\sa setRestartCommand(), restartHint()
*/
To iterate over the list, you can use the \l foreach pseudo-keyword:
- \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 11
+ \snippet code/src_gui_kernel_qapplication.cpp 11
\sa setDiscardCommand(), restartCommand(), setRestartCommand()
*/
Use the two-argument widgetAt() overload to get the child widget. To get
the top-level widget do this:
- \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 12
+ \snippet code/src_gui_kernel_qapplication.cpp 12
*/
/*!
Use the single-argument widgetAt() overload to get the child widget. To get
the top-level widget do this:
- \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 13
+ \snippet code/src_gui_kernel_qapplication.cpp 13
*/
bool QApplicationPrivate::inPopupMode() const
flash time, then hidden for the same amount of time, but this may vary.
The default value on X11 is 1000 milliseconds. On Windows, the
- \gui{Control Panel} value is used and setting this property sets the cursor
+ \uicontrol{Control Panel} value is used and setting this property sets the cursor
flash time for all applications.
We recommend that widgets do not cache this value as it may change at any
The simplest use of the class is like this:
- \snippet doc/src/snippets/layouts/layouts.cpp 0
- \snippet doc/src/snippets/layouts/layouts.cpp 1
- \snippet doc/src/snippets/layouts/layouts.cpp 2
+ \snippet layouts/layouts.cpp 0
+ \snippet layouts/layouts.cpp 1
+ \snippet layouts/layouts.cpp 2
\codeline
- \snippet doc/src/snippets/layouts/layouts.cpp 3
- \snippet doc/src/snippets/layouts/layouts.cpp 4
- \snippet doc/src/snippets/layouts/layouts.cpp 5
+ \snippet layouts/layouts.cpp 3
+ \snippet layouts/layouts.cpp 4
+ \snippet layouts/layouts.cpp 5
First, we create the widgets we want in the layout. Then, we
create the QHBoxLayout object and add the widgets into the
The simplest use of the class is like this:
- \snippet doc/src/snippets/layouts/layouts.cpp 6
- \snippet doc/src/snippets/layouts/layouts.cpp 7
- \snippet doc/src/snippets/layouts/layouts.cpp 8
+ \snippet layouts/layouts.cpp 6
+ \snippet layouts/layouts.cpp 7
+ \snippet layouts/layouts.cpp 8
\codeline
- \snippet doc/src/snippets/layouts/layouts.cpp 9
- \snippet doc/src/snippets/layouts/layouts.cpp 10
- \snippet doc/src/snippets/layouts/layouts.cpp 11
+ \snippet layouts/layouts.cpp 9
+ \snippet layouts/layouts.cpp 10
+ \snippet layouts/layouts.cpp 11
First, we create the widgets we want in the layout. Then, we
create the QVBoxLayout object and add the widgets into the
creates a QLabel behind the scenes and automatically set up
its buddy. We can then write code like this:
- \snippet doc/src/snippets/code/src_gui_kernel_qformlayout.cpp 0
+ \snippet code/src_gui_kernel_qformlayout.cpp 0
Compare this with the following code, written using QGridLayout:
- \snippet doc/src/snippets/code/src_gui_kernel_qformlayout.cpp 1
+ \snippet code/src_gui_kernel_qformlayout.cpp 1
\endlist
The table below shows the default appearance in different styles.
appearance of QMacStyle on all platforms, but with left-aligned
labels, you could write:
- \snippet doc/src/snippets/code/src_gui_kernel_qformlayout.cpp 2
+ \snippet code/src_gui_kernel_qformlayout.cpp 2
\sa QGridLayout, QBoxLayout, QStackedLayout
*/
resource, and then use it, allowing Qt to work out all the required
icon styles and sizes. For example:
- \snippet doc/src/snippets/code/src_gui_image_qicon.cpp 0
+ \snippet code/src_gui_image_qicon.cpp 0
To undo a QIcon, simply set a null icon in its place:
- \snippet doc/src/snippets/code/src_gui_image_qicon.cpp 1
+ \snippet code/src_gui_image_qicon.cpp 1
Use the QImageReader::supportedImageFormats() and
QImageWriter::supportedImageFormats() functions to retrieve a
Provide a method to set a QIcon, and when you draw the icon, choose
whichever pixmap is appropriate for the current state of your widget.
For example:
- \snippet doc/src/snippets/code/src_gui_image_qicon.cpp 2
+ \snippet code/src_gui_image_qicon.cpp 2
You might also make use of the \c Active mode, perhaps making your
widget \c Active when the mouse is over the widget (see \l
To fetch an icon from the current icon theme:
- \snippet doc/src/snippets/code/src_gui_image_qicon.cpp 3
+ \snippet code/src_gui_image_qicon.cpp 3
Or if you want to provide a guaranteed fallback for platforms that
do not support theme icons, you can use the second argument:
- \snippet doc/src/snippets/code/src_gui_image_qicon.cpp 4
+ \snippet code/src_gui_image_qicon.cpp 4
\note By default, only X11 will support themed icons. In order to
use themed icons on Mac and Windows, you will have to bundle a
This function can be used to iterate over a layout. The following
code will draw a rectangle for each layout item in the layout structure of the widget.
- \snippet doc/src/snippets/code/src_gui_kernel_qlayout.cpp 0
+ \snippet code/src_gui_kernel_qlayout.cpp 0
\sa count(), takeAt()
*/
The following code fragment shows a safe way to remove all items
from a layout:
- \snippet doc/src/snippets/code/src_gui_kernel_qlayout.cpp 1
+ \snippet code/src_gui_kernel_qlayout.cpp 1
\sa itemAt(), count()
*/
Reimplement this function in layout managers that support height
for width. A typical implementation will look like this:
- \snippet doc/src/snippets/code/src_gui_kernel_qlayoutitem.cpp 0
+ \snippet code/src_gui_kernel_qlayoutitem.cpp 0
Caching is strongly recommended; without it layout will take
exponential time.
objects can be informed when a shortcut is executed. The shortcut
can be set up to contain all the key presses necessary to
describe a keyboard shortcut, including the states of modifier
- keys such as \gui Shift, \gui Ctrl, and \gui Alt.
+ keys such as \uicontrol Shift, \uicontrol Ctrl, and \uicontrol Alt.
\target mnemonic
On certain widgets, using '&' in front of a character will
automatically create a mnemonic (a shortcut) for that character,
- e.g. "E&xit" will create the shortcut \gui Alt+X (use '&&' to
+ e.g. "E&xit" will create the shortcut \uicontrol Alt+X (use '&&' to
display an actual ampersand). The widget might consume and perform
an action on a given shortcut. On X11 the ampersand will not be
shown and the character will be underlined. On Windows, shortcuts
- are normally not displayed until the user presses the \gui Alt
+ are normally not displayed until the user presses the \uicontrol Alt
key, but this is a setting the user can change. On Mac, shortcuts
are disabled by default. Call qt_set_sequence_auto_mnemonic() to
enable them. However, because mnemonic shortcuts do not fit in
The simplest way to create a shortcut for a particular widget is
to construct the shortcut with a key sequence. For example:
- \snippet doc/src/snippets/code/src_gui_kernel_qshortcut.cpp 0
+ \snippet code/src_gui_kernel_qshortcut.cpp 0
When the user types the \l{QKeySequence}{key sequence}
for a given shortcut, the shortcut's activated() signal is
This is a key sequence with an optional combination of Shift, Ctrl,
and Alt. The key sequence may be supplied in a number of ways:
- \snippet doc/src/snippets/code/src_gui_kernel_qshortcut.cpp 1
+ \snippet code/src_gui_kernel_qshortcut.cpp 1
By default, this property contains an empty key sequence.
*/
A QStackedLayout can be populated with a number of child widgets
("pages"). For example:
- \snippet doc/src/snippets/qstackedlayout/main.cpp 0
+ \snippet qstackedlayout/main.cpp 0
\codeline
- \snippet doc/src/snippets/qstackedlayout/main.cpp 2
- \snippet doc/src/snippets/qstackedlayout/main.cpp 3
+ \snippet qstackedlayout/main.cpp 2
+ \snippet qstackedlayout/main.cpp 3
QStackedLayout provides no intrinsic means for the user to switch
page. This is typically done through a QComboBox or a QListWidget
that stores the titles of the QStackedLayout's pages. For
example:
- \snippet doc/src/snippets/qstackedlayout/main.cpp 1
+ \snippet qstackedlayout/main.cpp 1
When populating a layout, the widgets are added to an internal
list. The indexOf() function returns the index of a widget in that
simple method to determine whether the text can be rendered as
plain text. See Qt::mightBeRichText() for details.
- \snippet doc/src/snippets/whatsthis/whatsthis.cpp 0
+ \snippet whatsthis/whatsthis.cpp 0
An alternative way to enter "What's This?" mode is to call
createAction(), and add the returned QAction to either a menu or
windows, the change is immediate. For example, to toggle between
full-screen and normal mode, use the following code:
- \snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 0
+ \snippet code/src_gui_kernel_qwidget.cpp 0
In order to restore and activate a minimized window (while
preserving its maximized and/or full-screen state), use the following:
- \snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 1
+ \snippet code/src_gui_kernel_qwidget.cpp 1
Calling this function will hide the widget. You must call show() to make
the widget visible again.
sizeIncrement.height() pixels vertically, with baseSize() as the
basis. Preferred widget sizes are for non-negative integers \e i
and \e j:
- \snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 2
+ \snippet code/src_gui_kernel_qwidget.cpp 2
Note that while you can set the size increment for all widgets, it
only affects windows.
Typical usage is changing the window title:
- \snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 3
+ \snippet code/src_gui_kernel_qwidget.cpp 3
\sa isWindow()
*/
objects\endlink for a range of useful shapes.
An editor widget might use an I-beam cursor:
- \snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 6
+ \snippet code/src_gui_kernel_qwidget.cpp 6
If no cursor has been set, or after a call to unsetCursor(), the
parent's cursor is used.
using \a renderFlags to determine how to render. Rendering
starts at \a targetOffset in the \a target. For example:
- \snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 7
+ \snippet code/src_gui_kernel_qwidget.cpp 7
If \a sourceRegion is a null region, this function will use QWidget::rect() as
the region, i.e. the entire widget.
Ensure that you call QPainter::end() for the \a target device's
active painter (if any) before rendering. For example:
- \snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 8
+ \snippet code/src_gui_kernel_qwidget.cpp 8
\note To obtain the contents of an OpenGL widget, use QGLWidget::grabFrameBuffer()
or QGLWidget::renderPixmap() instead.
Note that since the tab order of the \a second widget is changed, you
should order a chain like this:
- \snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 9
+ \snippet code/src_gui_kernel_qwidget.cpp 9
\e not like this:
- \snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 10
+ \snippet code/src_gui_kernel_qwidget.cpp 10
If \a first or \a second has a focus proxy, setTabOrder()
correctly substitutes the proxy.
To save the geometry when the window closes, you can
implement a close event like this:
- \snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 11
+ \snippet code/src_gui_kernel_qwidget.cpp 11
See the \l{Window Geometry} documentation for an overview of geometry
issues with windows.
To restore geometry saved using QSettings, you can use code like
this:
- \snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 12
+ \snippet code/src_gui_kernel_qwidget.cpp 12
See the \l{Window Geometry} documentation for an overview of geometry
issues with windows.
widgets. Disabling updates solves this.
Example:
- \snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 13
+ \snippet code/src_gui_kernel_qwidget.cpp 13
Disabling a widget implicitly disables all its children. Enabling a widget
enables all child widgets \e except top-level widgets or those that
\b{Note for the X11 platform}: It is possible to toggle global double
buffering by calling \c qt_x11_set_global_double_buffer(). For example,
- \snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 14
+ \snippet code/src_gui_kernel_qwidget.cpp 14
\note Generally, you should refrain from calling update() or repaint()
\b{inside} a paintEvent(). For example, calling update() or repaint() on
Example:
- \snippet examples/uitools/textfinder/textfinder.cpp 3b
+ \snippet uitools/textfinder/textfinder.cpp 3b
An alternative to calling this function is to pass this widget to
the layout's constructor.
The following code shows how an image with an alpha channel can be
used to generate a mask for a widget:
- \snippet doc/src/snippets/widget-mask/main.cpp 0
+ \snippet widget-mask/main.cpp 0
The label shown by this code is masked using the image it contains,
giving the appearance that an irregularly-shaped image is being drawn
Alternatively you can use a QFrame widget and apply the
QFrame::setFrameStyle() function to display a shaded line:
- \snippet doc/src/snippets/code/src_gui_painting_qdrawutil.cpp 0
+ \snippet code/src_gui_painting_qdrawutil.cpp 0
\sa qDrawShadeRect(), qDrawShadePanel(), QStyle
*/
Alternatively you can use a QFrame widget and apply the
QFrame::setFrameStyle() function to display a shaded rectangle:
- \snippet doc/src/snippets/code/src_gui_painting_qdrawutil.cpp 1
+ \snippet code/src_gui_painting_qdrawutil.cpp 1
\sa qDrawShadeLine(), qDrawShadePanel(), qDrawPlainRect(), QStyle
*/
Alternatively you can use a QFrame widget and apply the
QFrame::setFrameStyle() function to display a shaded panel:
- \snippet doc/src/snippets/code/src_gui_painting_qdrawutil.cpp 2
+ \snippet code/src_gui_painting_qdrawutil.cpp 2
\sa qDrawWinPanel(), qDrawShadeLine(), qDrawShadeRect(), QStyle
*/
Alternatively you can use a QFrame widget and apply the
QFrame::setFrameStyle() function to display a shaded panel:
- \snippet doc/src/snippets/code/src_gui_painting_qdrawutil.cpp 3
+ \snippet code/src_gui_painting_qdrawutil.cpp 3
\sa qDrawShadePanel(), qDrawWinButton(), QStyle
*/
Alternatively you can use a QFrame widget and apply the
QFrame::setFrameStyle() function to display a plain rectangle:
- \snippet doc/src/snippets/code/src_gui_painting_qdrawutil.cpp 4
+ \snippet code/src_gui_painting_qdrawutil.cpp 4
\sa qDrawShadeRect(), QStyle
*/
Alternatively you can use a QFrame widget and apply the
QFrame::setFrameStyle() function to display a shaded line:
- \snippet doc/src/snippets/code/src_gui_painting_qdrawutil.cpp 5
+ \snippet code/src_gui_painting_qdrawutil.cpp 5
\sa qDrawShadeRect(), qDrawShadePanel(), QStyle
*/
Alternatively you can use a QFrame widget and apply the
QFrame::setFrameStyle() function to display a shaded rectangle:
- \snippet doc/src/snippets/code/src_gui_painting_qdrawutil.cpp 6
+ \snippet code/src_gui_painting_qdrawutil.cpp 6
\sa qDrawShadeLine(), qDrawShadePanel(), qDrawPlainRect(), QStyle
*/
Alternatively you can use a QFrame widget and apply the
QFrame::setFrameStyle() function to display a shaded panel:
- \snippet doc/src/snippets/code/src_gui_painting_qdrawutil.cpp 7
+ \snippet code/src_gui_painting_qdrawutil.cpp 7
\sa qDrawWinPanel(), qDrawShadeLine(), qDrawShadeRect(), QStyle
*/
Alternatively you can use a QFrame widget and apply the
QFrame::setFrameStyle() function to display a shaded panel:
- \snippet doc/src/snippets/code/src_gui_painting_qdrawutil.cpp 8
+ \snippet code/src_gui_painting_qdrawutil.cpp 8
\sa qDrawShadePanel(), qDrawWinButton(), QStyle
*/
Alternatively you can use a QFrame widget and apply the
QFrame::setFrameStyle() function to display a plain rectangle:
- \snippet doc/src/snippets/code/src_gui_painting_qdrawutil.cpp 9
+ \snippet code/src_gui_painting_qdrawutil.cpp 9
\sa qDrawShadeRect(), QStyle
*/
The following example shows how to override the shortcut underline
behavior on any platform:
- \snippet doc/src/snippets/code/src_gui_qproxystyle.cpp 1
+ \snippet code/src_gui_qproxystyle.cpp 1
Warning: The \l {QCommonStyle} {common styles} provided by Qt will
respect this hint, because they call QStyle::proxy(), but there is
QApplication::setStyle() function. It can also be specified by the
user of the application, using the \c -style command-line option:
- \snippet doc/src/snippets/code/src_gui_styles_qstyle.cpp 0
+ \snippet code/src_gui_styles_qstyle.cpp 0
If no style is specified, Qt will choose the most appropriate
style for the user's platform or desktop environment.
For example, if you want to draw a focus rectangle on your
widget, you can write:
- \snippet doc/src/snippets/styles/styles.cpp 1
+ \snippet styles/styles.cpp 1
QStyle gets all the information it needs to render the graphical
element from QStyleOption. The widget is passed as the last
combines a QStyle, a QPainter, and a QWidget. This makes it
possible to write
- \snippet doc/src/snippets/styles/styles.cpp 5
+ \snippet styles/styles.cpp 5
\dots
- \snippet doc/src/snippets/styles/styles.cpp 7
+ \snippet styles/styles.cpp 7
instead of
- \snippet doc/src/snippets/styles/styles.cpp 2
+ \snippet styles/styles.cpp 2
\dots
- \snippet doc/src/snippets/styles/styles.cpp 3
+ \snippet styles/styles.cpp 3
\section1 Creating a Custom Style
function, so we need to reimplement that function. We need the
following class declaration:
- \snippet doc/src/snippets/customstyle/customstyle.h 0
+ \snippet customstyle/customstyle.h 0
To draw its up and down arrows, QSpinBox uses the
PE_IndicatorSpinUp and PE_IndicatorSpinDown primitive elements.
Here's how to reimplement the drawPrimitive() function to draw
them differently:
- \snippet doc/src/snippets/customstyle/customstyle.cpp 2
- \snippet doc/src/snippets/customstyle/customstyle.cpp 3
- \snippet doc/src/snippets/customstyle/customstyle.cpp 4
+ \snippet customstyle/customstyle.cpp 2
+ \snippet customstyle/customstyle.cpp 3
+ \snippet customstyle/customstyle.cpp 4
Notice that we don't use the \c widget argument, except to pass it
on to the QWindowStyle::drawPrimitive() function. As mentioned
information, be careful to ensure that it isn't 0 and that it is
of the correct type before using it. For example:
- \snippet doc/src/snippets/customstyle/customstyle.cpp 0
+ \snippet customstyle/customstyle.cpp 0
\dots
- \snippet doc/src/snippets/customstyle/customstyle.cpp 1
+ \snippet customstyle/customstyle.cpp 1
When implementing a custom style, you cannot assume that the
widget is a QSpinBox just because the enum value is called
QApplication::setStyle() static function before creating the
QApplication object:
- \snippet snippets/customstyle/main.cpp using a custom style
+ \snippet customstyle/main.cpp using a custom style
You can call QApplication::setStyle() at any time, but by calling
it before the constructor, you ensure that the user's preference,
automatically. To use your new style with existing applications,
simply start the application with the following argument:
- \snippet doc/src/snippets/code/src_gui_styles_qstyle.cpp 1
+ \snippet code/src_gui_styles_qstyle.cpp 1
The application will use the look and feel from the custom style you
implemented.
We include a small example where we customize the drawing of item
backgrounds.
- \snippet doc/src/snippets/customviewstyle.cpp 0
+ \snippet customviewstyle.cpp 0
The primitive element PE_PanelItemViewItem is responsible for
painting the background of items, and is called from
The following code snippet shows how to use a specific
QStyleOption subclass to paint a push button:
- \snippet doc/src/snippets/qstyleoption/main.cpp 0
+ \snippet qstyleoption/main.cpp 0
In our example, the control is a QStyle::CE_PushButton, and
according to the QStyle::drawControl() documentation the
For safety, you can use qstyleoption_cast() to ensure that the
pointer type is correct. For example:
- \snippet doc/src/snippets/qstyleoption/main.cpp 4
+ \snippet qstyleoption/main.cpp 4
The qstyleoption_cast() function will return 0 if the object to
which \c option points is not of the correct type.
Example:
- \snippet doc/src/snippets/qstyleoption/main.cpp 4
+ \snippet qstyleoption/main.cpp 4
\sa QStyleOption::type, QStyleOption::version
*/
Example:
- \snippet doc/src/snippets/code/src_gui_styles_qstyleoption.cpp 0
+ \snippet code/src_gui_styles_qstyleoption.cpp 0
\sa QStyleHintReturn::type, QStyleHintReturn::version
*/
Example using QStyle directly:
- \snippet doc/src/snippets/styles/styles.cpp 1
+ \snippet styles/styles.cpp 1
Example using QStylePainter:
- \snippet doc/src/snippets/styles/styles.cpp 0
- \snippet doc/src/snippets/styles/styles.cpp 4
- \snippet doc/src/snippets/styles/styles.cpp 6
+ \snippet styles/styles.cpp 0
+ \snippet styles/styles.cpp 4
+ \snippet styles/styles.cpp 6
\sa QStyle, QStyleOption
*/
The style key is usually the class name of the required
style. Note that the keys are case insensitive. For example:
- \snippet doc/src/snippets/qstyleplugin/main.cpp 0
+ \snippet qstyleplugin/main.cpp 0
\codeline
- \snippet doc/src/snippets/qstyleplugin/main.cpp 1
- \snippet doc/src/snippets/qstyleplugin/main.cpp 2
+ \snippet qstyleplugin/main.cpp 1
+ \snippet qstyleplugin/main.cpp 2
\sa keys()
*/
For example, here's how to provide auto completions from a simple
word list in a QLineEdit:
- \snippet doc/src/snippets/code/src_gui_util_qcompleter.cpp 0
+ \snippet code/src_gui_util_qcompleter.cpp 0
A QFileSystemModel can be used to provide auto completion of file names.
For example:
- \snippet doc/src/snippets/code/src_gui_util_qcompleter.cpp 1
+ \snippet code/src_gui_util_qcompleter.cpp 1
To set the model on which QCompleter should operate, call
setModel(). By default, QCompleter will attempt to match the \l
currentCompletion(). You can iterate through the list of
completions as below:
- \snippet doc/src/snippets/code/src_gui_util_qcompleter.cpp 2
+ \snippet code/src_gui_util_qcompleter.cpp 2
completionCount() returns the total number of completions for the
current prefix. completionCount() should be avoided when possible,
a change to the document with redo() and undo the change with undo(). The
implementations for these functions must be provided in a derived class.
- \snippet doc/src/snippets/code/src_gui_util_qundostack.cpp 0
+ \snippet code/src_gui_util_qundostack.cpp 0
A QUndoCommand has an associated text(). This is a short string
describing what the command does. It is used to update the text
QUndoCommand objects are owned by the stack they were pushed on.
QUndoStack deletes a command if it has been undone and a new command is pushed. For example:
-\snippet doc/src/snippets/code/src_gui_util_qundostack.cpp 1
+\snippet code/src_gui_util_qundostack.cpp 1
In effect, when a command is pushed, it becomes the top-most command
on the stack.
redo() on all its children. The parent should, however, have a meaningful
text().
- \snippet doc/src/snippets/code/src_gui_util_qundostack.cpp 2
+ \snippet code/src_gui_util_qundostack.cpp 2
Another way to create macros is to use the convenience functions
QUndoStack::beginMacro() and QUndoStack::endMacro().
The default implementation returns false.
- \snippet doc/src/snippets/code/src_gui_util_qundostack.cpp 3
+ \snippet code/src_gui_util_qundostack.cpp 3
\sa id() QUndoStack::push()
*/
The stack becomes enabled and appropriate signals are emitted when endMacro()
is called for the outermost macro.
- \snippet doc/src/snippets/code/src_gui_util_qundostack.cpp 4
+ \snippet code/src_gui_util_qundostack.cpp 4
This code is equivalent to:
- \snippet doc/src/snippets/code/src_gui_util_qundostack.cpp 5
+ \snippet code/src_gui_util_qundostack.cpp 5
\sa endMacro()
*/
ampersand ('&'), QAbstractButton automatically creates a shortcut
key. For example:
- \snippet doc/src/snippets/code/src_gui_widgets_qabstractbutton.cpp 0
+ \snippet code/src_gui_widgets_qabstractbutton.cpp 0
The \key Alt+C shortcut is assigned to the button, i.e., when the
user presses \key Alt+C the button will call animateClick(). See
function. This is useful mostly for buttons that do not have any
text, because they have no automatic shortcut.
- \snippet doc/src/snippets/code/src_gui_widgets_qabstractbutton.cpp 1
+ \snippet code/src_gui_widgets_qabstractbutton.cpp 1
All of the buttons provided by Qt (QPushButton, QToolButton,
QCheckBox, and QRadioButton) can display both \l text and \l{icon}{icons}.
buttons but which ignores signals from buttons that have been unchecked
can be implemented using the following pattern:
-\snippet doc/src/snippets/code/src_gui_widgets_qabstractbutton.cpp 2
+\snippet code/src_gui_widgets_qabstractbutton.cpp 2
Button groups can be created using the QButtonGroup class, and
updates to the button states monitored with the
QWidget::move(). When the area contents or the viewport size
changes, we do the following:
- \snippet doc/src/snippets/myscrollarea.cpp 1
+ \snippet myscrollarea.cpp 1
When the scroll bars change value, we need to update the widget
position, i.e., find the part of the widget that is to be drawn in
the viewport:
- \snippet doc/src/snippets/myscrollarea.cpp 0
+ \snippet myscrollarea.cpp 0
In order to track scroll bar movements, reimplement the virtual
function scrollContentsBy(). In order to fine-tune scrolling
to automatically choose one that will enable the image to fit completely
within the display window, you can set up the spin box like this:
- \snippet examples/widgets/spinboxes/window.cpp 3
+ \snippet widgets/spinboxes/window.cpp 3
The user will then be able to choose a scale from 1% to 1000%
or select "Auto" to leave it up to the application to choose. Your code
to the minimum() value and vica versa. Wrapping only make sense if
you have minimum() and maximum() values set.
- \snippet doc/src/snippets/code/src_gui_widgets_qabstractspinbox.cpp 0
+ \snippet code/src_gui_widgets_qabstractspinbox.cpp 0
\sa QSpinBox::minimum(), QSpinBox::maximum()
*/
\row \li
\image qcalendarwidget-grid.png
\row \li
- \snippet doc/src/snippets/code/src_gui_widgets_qcalendarwidget.cpp 0
+ \snippet code/src_gui_widgets_qcalendarwidget.cpp 0
\endtable
Finally, the day in the first column can be altered using the
\li \image qcalendarwidget-minimum.png
\row
\li
- \snippet doc/src/snippets/code/src_gui_widgets_qcalendarwidget.cpp 1
+ \snippet code/src_gui_widgets_qcalendarwidget.cpp 1
\endtable
By default, the minimum date is the earliest date that the QDate
\li \image qcalendarwidget-maximum.png
\row
\li
- \snippet doc/src/snippets/code/src_gui_widgets_qcalendarwidget.cpp 2
+ \snippet code/src_gui_widgets_qcalendarwidget.cpp 2
\endtable
By default, the maximum date is the last day the QDate class can
The date range restricts the user selection, i.e. the user can
only select dates within the specified date range. Note that
- \snippet doc/src/snippets/code/src_gui_widgets_qcalendarwidget.cpp 3
+ \snippet code/src_gui_widgets_qcalendarwidget.cpp 3
is analogous to
- \snippet doc/src/snippets/code/src_gui_widgets_qcalendarwidget.cpp 4
+ \snippet code/src_gui_widgets_qcalendarwidget.cpp 4
If either the \a min or \a max parameters are not valid QDate
objects, this function does nothing.
\li \inlineimage qcalendarwidget-grid.png
\row
\li
- \snippet doc/src/snippets/code/src_gui_widgets_qcalendarwidget.cpp 5
+ \snippet code/src_gui_widgets_qcalendarwidget.cpp 5
\endtable
The default value is false.
constructor or with setText(). A shortcut key can be specified by preceding
the preferred character with an ampersand. For example:
- \snippet doc/src/snippets/code/src_gui_widgets_qcheckbox.cpp 0
+ \snippet code/src_gui_widgets_qcheckbox.cpp 0
In this example the shortcut is \e{Alt+A}. See the \l{QShortcut#mnemonic}
{QShortcut} documentation for details (to display an actual ampersand,
QDateTimeEdit box. Dates and times appear in accordance with the
format set; see setDisplayFormat().
- \snippet doc/src/snippets/code/src_gui_widgets_qdatetimeedit.cpp 0
+ \snippet code/src_gui_widgets_qdatetimeedit.cpp 0
Here we've created a new QDateTimeEdit object initialized with
today's date, and restricted the valid date range to today plus or
function call.
\since 4.4
- \snippet doc/src/snippets/code/src_gui_widgets_qdatetimeedit.cpp 1
+ \snippet code/src_gui_widgets_qdatetimeedit.cpp 1
is analogous to:
- \snippet doc/src/snippets/code/src_gui_widgets_qdatetimeedit.cpp 2
+ \snippet code/src_gui_widgets_qdatetimeedit.cpp 2
If either \a min or \a max are not valid, this function does
nothing.
Convenience function to set minimum and maximum date with one
function call.
- \snippet doc/src/snippets/code/src_gui_widgets_qdatetimeedit.cpp 3
+ \snippet code/src_gui_widgets_qdatetimeedit.cpp 3
is analogous to:
- \snippet doc/src/snippets/code/src_gui_widgets_qdatetimeedit.cpp 4
+ \snippet code/src_gui_widgets_qdatetimeedit.cpp 4
If either \a min or \a max are not valid, this function does
nothing.
Convenience function to set minimum and maximum time with one
function call.
- \snippet doc/src/snippets/code/src_gui_widgets_qdatetimeedit.cpp 5
+ \snippet code/src_gui_widgets_qdatetimeedit.cpp 5
is analogous to:
- \snippet doc/src/snippets/code/src_gui_widgets_qdatetimeedit.cpp 6
+ \snippet code/src_gui_widgets_qdatetimeedit.cpp 6
If either \a min or \a max are not valid, this function does
nothing.
destructive results.
Most dialogs have buttons that can almost be considered standard (e.g.
- \gui OK and \gui Cancel buttons). It is sometimes convenient to create these
+ \uicontrol OK and \uicontrol Cancel buttons). It is sometimes convenient to create these
buttons in a standard way.
There are a couple ways of using QDialogButtonBox. One ways is to create
the buttons (or button texts) yourself and add them to the button box,
specifying their role.
- \snippet examples/dialogs/extension/finddialog.cpp 1
+ \snippet dialogs/extension/finddialog.cpp 1
Alternatively, QDialogButtonBox provides several standard buttons (e.g. OK, Cancel, Save)
that you can use. They exist as flags so you can OR them together in the constructor.
- \snippet examples/dialogs/tabdialog/tabdialog.cpp 2
+ \snippet dialogs/tabdialog/tabdialog.cpp 2
You can mix and match normal buttons and standard buttons.
\table
\row \li modeless horizontal MacLayout
\li \inlineimage buttonbox-mac-modeless-horizontal.png Screenshot of modeless horizontal MacLayout
+ \row \li modeless vertical MacLayout
+ \li \inlineimage buttonbox-mac-modeless-vertical.png Screenshot of modeless vertical MacLayout
\endtable
When a button is clicked in the button box, the clicked() signal is emitted
\li When DockWidgetVerticalTitleBar is set on QDockWidget, the title
bar widget is repositioned accordingly. In resizeEvent(), the title
bar should check what orientation it should assume:
- \snippet doc/src/snippets/code/src_gui_widgets_qdockwidget.cpp 0
+ \snippet code/src_gui_widgets_qdockwidget.cpp 0
\li The title bar widget must have a valid QWidget::sizeHint() and
QWidget::minimumSizeHint(). These functions should take into account
screen. QProgressBar has a "sunken" look. QLabel has a flat look.
The frames of widgets like these can be changed.
- \snippet doc/src/snippets/code/src_gui_widgets_qframe.cpp 0
+ \snippet code/src_gui_widgets_qframe.cpp 0
The QFrame class can also be used directly for creating simple
placeholder frames without any contents.
widgets). The following example shows how we can set up a
QGroupBox with a layout:
- \snippet examples/widgets/groupbox/window.cpp 2
+ \snippet widgets/groupbox/window.cpp 2
\table 100%
\row \li \inlineimage windowsxp-groupbox.png Screenshot of a Windows XP style group box
The group box title text will have a keyboard shortcut if the title
contains an ampersand ('&') followed by a letter.
- \snippet doc/src/snippets/code/src_gui_widgets_qgroupbox.cpp 0
+ \snippet code/src_gui_widgets_qgroupbox.cpp 0
In the example above, \key Alt+U moves the keyboard focus to the
group box. See the \l {QShortcut#mnemonic}{QShortcut}
the bottom right corner (both lines being flush with the right
side of the label):
- \snippet doc/src/snippets/code/src_gui_widgets_qlabel.cpp 0
+ \snippet code/src_gui_widgets_qlabel.cpp 0
The properties and functions QLabel inherits from QFrame can also
be used to specify the widget frame to be used for any given label.
mnemonic (see QKeySequence) that will set the keyboard focus to
the other widget (called the QLabel's "buddy"). For example:
- \snippet doc/src/snippets/code/src_gui_widgets_qlabel.cpp 1
+ \snippet code/src_gui_widgets_qlabel.cpp 1
In this example, keyboard focus is transferred to the label's
buddy (the QLineEdit) when the user presses Alt+P. If the buddy
In a dialog, you might create two data entry widgets and a label
for each, and set up the geometry layout so each label is just to
the left of its data entry widget (its "buddy"), for example:
- \snippet doc/src/snippets/code/src_gui_widgets_qlabel.cpp 2
+ \snippet code/src_gui_widgets_qlabel.cpp 2
With the code above, the focus jumps to the Name field when the
user presses Alt+N, and to the Phone field when the user presses
to extend the standard context menu, reimplement this function, call
createStandardContextMenu() and extend the menu returned.
- \snippet doc/src/snippets/code/src_gui_widgets_qlineedit.cpp 0
+ \snippet code/src_gui_widgets_qlineedit.cpp 0
The \a event parameter is used to obtain the position where
the mouse cursor was when the event was generated.
developer to provide the autorelease pool.
The following is a snippet of subclassing QMacCocoaViewContainer to wrap a NSSearchField.
- \snippet examples/mainwindows/macmainwindow/macmainwindow.mm 0
+ \snippet mainwindows/macmainwindow/macmainwindow.mm 0
*/
Here is an example of putting a QPushButton into a NSWindow:
- \snippet doc/src/snippets/qmacnativewidget/main.mm 0
+ \snippet qmacnativewidget/main.mm 0
On Carbon, this would do the equivalent:
- \snippet doc/src/snippets/qmacnativewidget/main.mm 1
+ \snippet qmacnativewidget/main.mm 1
Note that QMacNativeWidget requires knowledge of Carbon or Cocoa. All it
does is get the Qt hierarchy into a window not owned by Qt. It is then up
An example of how to create menus follows:
- \snippet examples/mainwindows/application/mainwindow.cpp 26
+ \snippet mainwindows/application/mainwindow.cpp 26
The \c createPopupMenu() function creates popup menus when the
main window receives context menu events. The default
An example of toolbar creation follows:
- \snippet examples/mainwindows/application/mainwindow.cpp 29
+ \snippet mainwindows/application/mainwindow.cpp 29
\section2 Creating Dock Widgets
We give an example of how to create and add dock widgets to a
main window:
- \snippet doc/src/snippets/mainwindowsnippet.cpp 0
+ \snippet mainwindowsnippet.cpp 0
\section2 The Status Bar
can then share among all the Mac windows. Create a parent-less
menu bar this way:
- \snippet doc/src/snippets/code/src_gui_widgets_qmenubar.cpp 1
+ \snippet code/src_gui_widgets_qmenubar.cpp 1
\sa setMenuBar()
*/
To save the geometry when the window closes, you can
implement a close event like this:
- \snippet doc/src/snippets/code/src_gui_widgets_qmainwindow.cpp 0
+ \snippet code/src_gui_widgets_qmainwindow.cpp 0
\sa restoreState(), QWidget::saveGeometry(), QWidget::restoreGeometry()
*/
To restore geometry saved using QSettings, you can use code like
this:
- \snippet doc/src/snippets/code/src_gui_widgets_qmainwindow.cpp 1
+ \snippet code/src_gui_widgets_qmainwindow.cpp 1
\sa saveState(), QWidget::saveGeometry(),
QWidget::restoreGeometry(), restoreDockWidget()
applications, but can also be placed in any layout. The following
code adds an area to a main window:
- \snippet doc/src/snippets/mdiareasnippets.cpp 0
+ \snippet mdiareasnippets.cpp 0
Unlike the window managers for top-level windows, all window flags
(Qt::WindowFlags) are supported by QMdiArea as long as the flags
\note Once the subwindow has been added, its parent will be the
\e{viewport widget} of the QMdiArea.
- \snippet doc/src/snippets/mdiareasnippets.cpp 1
+ \snippet mdiareasnippets.cpp 1
When you create your own subwindow, you must set the
Qt::WA_DeleteOnClose widget attribute if you want the window to be
In most situations you'll want to specify the position yourself,
for example, the current mouse position:
- \snippet doc/src/snippets/code/src_gui_widgets_qmenu.cpp 0
+ \snippet code/src_gui_widgets_qmenu.cpp 0
or aligned to a widget:
- \snippet doc/src/snippets/code/src_gui_widgets_qmenu.cpp 1
+ \snippet code/src_gui_widgets_qmenu.cpp 1
or in reaction to a QMouseEvent *e:
- \snippet doc/src/snippets/code/src_gui_widgets_qmenu.cpp 2
+ \snippet code/src_gui_widgets_qmenu.cpp 2
*/
QAction *QMenu::exec()
{
Common usage is to position the menu at the current mouse
position:
- \snippet doc/src/snippets/code/src_gui_widgets_qmenu.cpp 3
+ \snippet code/src_gui_widgets_qmenu.cpp 3
or aligned to a widget:
- \snippet doc/src/snippets/code/src_gui_widgets_qmenu.cpp 4
+ \snippet code/src_gui_widgets_qmenu.cpp 4
or in reaction to a QMouseEvent *e:
- \snippet doc/src/snippets/code/src_gui_widgets_qmenu.cpp 5
+ \snippet code/src_gui_widgets_qmenu.cpp 5
When positioning a menu with exec() or popup(), bear in mind that
you cannot rely on the menu's current size(). For performance
(normally because the user pressed Esc).
This is equivalent to:
- \snippet doc/src/snippets/code/src_gui_widgets_qmenu.cpp 6
+ \snippet code/src_gui_widgets_qmenu.cpp 6
\sa popup(), QWidget::mapToGlobal()
*/
menu items with addMenu(). For example, asuming that \c menubar
is a pointer to a QMenuBar and \c fileMenu is a pointer to a
QMenu, the following statement inserts the menu into the menu bar:
- \snippet doc/src/snippets/code/src_gui_widgets_qmenubar.cpp 0
+ \snippet code/src_gui_widgets_qmenubar.cpp 0
The ampersand in the menu item's text sets Alt+F as a shortcut for
this menu. (You can use "\&\&" to get a real ampersand in the menu
Example (from the \l{mainwindows/menus}{Menus} example):
- \snippet examples/mainwindows/menus/mainwindow.cpp 9
+ \snippet mainwindows/menus/mainwindow.cpp 9
Menu items may be removed with removeAction().
of menu bars and their behavior when the user interacts with them.
For example, Windows systems are often configured so that the
underlined character mnemonics that indicate keyboard shortcuts
- for items in the menu bar are only shown when the \gui{Alt} key is
+ for items in the menu bar are only shown when the \uicontrol{Alt} key is
pressed.
\table
Plastique widget style.
\li The \l{QPlastiqueStyle}{Plastique widget style}, like most
- other styles, handles the \gui{Help} menu in the same way as it
+ other styles, handles the \uicontrol{Help} menu in the same way as it
handles any other menu.
\row \li \inlineimage motif-menubar.png A menu bar shown in the
Motif widget style.
- \li The \l{QMotifStyle}{Motif widget style} treats \gui{Help} menus
+ \li The \l{QMotifStyle}{Motif widget style} treats \uicontrol{Help} menus
in a special way, placing them at right-hand end of the menu bar.
\endtable
bar, you must create a menu bar that does not have a parent.
Create a parent-less menu bar this way:
- \snippet doc/src/snippets/code/src_gui_widgets_qmenubar.cpp 1
+ \snippet code/src_gui_widgets_qmenubar.cpp 1
\b{Note:} Do \e{not} call QMainWindow::menuBar() to create the
shared menu bar, because that menu bar will have the QMainWindow
Information about the event is passed in the \a event object.
- \snippet doc/src/snippets/code/src_gui_widgets_qplaintextedit.cpp 0
+ \snippet code/src_gui_widgets_qplaintextedit.cpp 0
*/
void QPlainTextEdit::contextMenuEvent(QContextMenuEvent *e)
{
It is equivalent to
- \snippet doc/src/snippets/code/src_gui_widgets_qplaintextedit.cpp 1
+ \snippet code/src_gui_widgets_qplaintextedit.cpp 1
*/
void QPlainTextEdit::insertPlainText(const QString &text)
{
#endif
/*! \property QPlainTextEdit::tabChangesFocus
- \brief whether \gui Tab changes focus or is accepted as input
+ \brief whether \uicontrol Tab changes focus or is accepted as input
In some occasions text edits should not allow the user to input
- tabulators or change indentation using the \gui Tab key, as this breaks
+ tabulators or change indentation using the \uicontrol Tab key, as this breaks
the focus chain. The default is false.
*/
preceding the preferred character with an ampersand in the
text. For example:
- \snippet doc/src/snippets/code/src_gui_widgets_qpushbutton.cpp 0
+ \snippet code/src_gui_widgets_qpushbutton.cpp 0
In this example the shortcut is \e{Alt+D}. See the \l
{QShortcut#mnemonic}{QShortcut} documentation for details (to
can be specified by preceding the preferred character with an
ampersand in the text. For example:
- \snippet doc/src/snippets/code/src_gui_widgets_qradiobutton.cpp 0
+ \snippet code/src_gui_widgets_qradiobutton.cpp 0
In this example the shortcut is \e{Alt+c}. See the \l
{QShortcut#mnemonic}{QShortcut} documentation for details (to
setGeometry(), move() or resize() to position and size it. A common
pattern is to do this in conjunction with mouse events. For example:
- \snippet doc/src/snippets/code/src_gui_widgets_qrubberband.cpp 0
+ \snippet code/src_gui_widgets_qrubberband.cpp 0
If you pass a parent to QRubberBand's constructor, the rubber band will
display only inside its parent, but stays on top of other child widgets.
widget can be viewed. The child widget must be specified with
setWidget(). For example:
- \snippet doc/src/snippets/code/src_gui_widgets_qscrollarea.cpp 0
+ \snippet code/src_gui_widgets_qscrollarea.cpp 0
The code above creates a scroll area (shown in the images below)
containing an image label. When scaling the image, the scroll area
for a custom spin box that allows the user to enter icon sizes
(e.g., "32 x 32"):
- \snippet examples/widgets/icons/iconsizespinbox.cpp 1
+ \snippet widgets/icons/iconsizespinbox.cpp 1
\codeline
- \snippet examples/widgets/icons/iconsizespinbox.cpp 2
+ \snippet widgets/icons/iconsizespinbox.cpp 2
See the \l{widgets/icons}{Icons} example for the full source
code.
Typical use is to display a unit of measurement or a currency
symbol. For example:
- \snippet doc/src/snippets/code/src_gui_widgets_qspinbox.cpp 0
+ \snippet code/src_gui_widgets_qspinbox.cpp 0
To turn off the prefix display, set this property to an empty
string. The default is no prefix. The prefix is not displayed when
use is to display a unit of measurement or a currency symbol. For
example:
- \snippet doc/src/snippets/code/src_gui_widgets_qspinbox.cpp 1
+ \snippet code/src_gui_widgets_qspinbox.cpp 1
To turn off the suffix display, set this property to an empty
string. The default is no suffix. The suffix is not displayed for
Convenience function to set the \a minimum, and \a maximum values
with a single function call.
- \snippet doc/src/snippets/code/src_gui_widgets_qspinbox.cpp 2
+ \snippet code/src_gui_widgets_qspinbox.cpp 2
is equivalent to:
- \snippet doc/src/snippets/code/src_gui_widgets_qspinbox.cpp 3
+ \snippet code/src_gui_widgets_qspinbox.cpp 3
\sa minimum maximum
*/
Typical use is to display a unit of measurement or a currency
symbol. For example:
- \snippet doc/src/snippets/code/src_gui_widgets_qspinbox.cpp 4
+ \snippet code/src_gui_widgets_qspinbox.cpp 4
To turn off the prefix display, set this property to an empty
string. The default is no prefix. The prefix is not displayed when
use is to display a unit of measurement or a currency symbol. For
example:
- \snippet doc/src/snippets/code/src_gui_widgets_qspinbox.cpp 5
+ \snippet code/src_gui_widgets_qspinbox.cpp 5
To turn off the suffix display, set this property to an empty
string. The default is no suffix. The suffix is not displayed for
Note: The maximum and minimum values will be rounded to match the
decimals property.
- \snippet doc/src/snippets/code/src_gui_widgets_qspinbox.cpp 6
+ \snippet code/src_gui_widgets_qspinbox.cpp 6
is equivalent to:
- \snippet doc/src/snippets/code/src_gui_widgets_qspinbox.cpp 7
+ \snippet code/src_gui_widgets_qspinbox.cpp 7
\sa minimum maximum
*/
some initialization tasks are performed before the application's
main window is shown:
- \snippet doc/src/snippets/qsplashscreen/main.cpp 0
+ \snippet qsplashscreen/main.cpp 0
\dots
- \snippet doc/src/snippets/qsplashscreen/main.cpp 1
+ \snippet qsplashscreen/main.cpp 1
The user can hide the splash screen by clicking on it with the
mouse. Since the splash screen is typically displayed before the
for example, announcing connections established or modules loaded
as the application starts up:
- \snippet doc/src/snippets/code/src_gui_widgets_qsplashscreen.cpp 0
+ \snippet code/src_gui_widgets_qsplashscreen.cpp 0
QSplashScreen supports this with the showMessage() function. If you
wish to do your own drawing you can get a pointer to the pixmap
reimplement QSplitter::createHandle() to instantiate the custom splitter
handle. For example, a minimum QSplitter subclass might look like this:
- \snippet doc/src/snippets/splitterhandle/splitter.h 0
+ \snippet splitterhandle/splitter.h 0
The \l{QSplitter::}{createHandle()} implementation simply constructs a
custom splitter handle, called \c Splitter in this example:
- \snippet doc/src/snippets/splitterhandle/splitter.cpp 1
+ \snippet splitterhandle/splitter.cpp 1
Information about a given handle can be obtained using functions like
orientation() and opaqueResize(), and is retrieved from its parent splitter.
needs to perform. A simple subclass might only provide a paintEvent()
implementation:
- \snippet doc/src/snippets/splitterhandle/splitter.cpp 0
+ \snippet splitterhandle/splitter.cpp 0
In this example, a predefined gradient is set up differently depending on
the orientation of the handle. QSplitterHandle provides a reasonable
The following example will show a QListView, QTreeView, and
QTextEdit side by side, with two splitter handles:
- \snippet doc/src/snippets/splitter/splitter.cpp 0
+ \snippet splitter/splitter.cpp 0
If a widget is already inside a QSplitter when insertWidget() or
addWidget() is called, it will move to the new position. This can be used
for a future session. A version number is stored as part of the data.
Here is an example:
- \snippet doc/src/snippets/splitter/splitter.cpp 1
+ \snippet splitter/splitter.cpp 1
\sa restoreState()
*/
Restore the splitters's state:
- \snippet doc/src/snippets/splitter/splitter.cpp 2
+ \snippet splitter/splitter.cpp 2
A failure to restore the splitter's layout may result from either
invalid or out-of-date data in the supplied byte array.
This function is provided for convenience. It is equivalent to
- \snippet doc/src/snippets/code/src_gui_widgets_qsplitter.cpp 0
+ \snippet code/src_gui_widgets_qsplitter.cpp 0
\sa setSizes(), widget()
*/
Like QStackedLayout, QStackedWidget can be constructed and
populated with a number of child widgets ("pages"):
- \snippet doc/src/snippets/qstackedwidget/main.cpp 0
- \snippet doc/src/snippets/qstackedwidget/main.cpp 2
- \snippet doc/src/snippets/qstackedwidget/main.cpp 3
+ \snippet qstackedwidget/main.cpp 0
+ \snippet qstackedwidget/main.cpp 2
+ \snippet qstackedwidget/main.cpp 3
QStackedWidget provides no intrinsic means for the user to switch
page. This is typically done through a QComboBox or a QListWidget
that stores the titles of the QStackedWidget's pages. For
example:
- \snippet doc/src/snippets/qstackedwidget/main.cpp 1
+ \snippet qstackedwidget/main.cpp 1
When populating a stacked widget, the widgets are added to an
internal list. The indexOf() function returns the index of a
Use the showMessage() slot to display a \e temporary message:
- \snippet examples/mainwindows/dockwidgets/mainwindow.cpp 8
+ \snippet mainwindows/dockwidgets/mainwindow.cpp 8
To remove a temporary message, use the clearMessage() slot, or set
a time limit when calling showMessage(). For example:
- \snippet examples/mainwindows/dockwidgets/mainwindow.cpp 3
+ \snippet mainwindows/dockwidgets/mainwindow.cpp 3
Use the currentMessage() function to retrieve the temporary
message currently shown. The QStatusBar class also provide the
addPermanentWidget() function. Use the removeWidget() function to
remove such messages from the status bar.
- \snippet doc/src/snippets/code/src_gui_widgets_qstatusbar.cpp 0
+ \snippet code/src_gui_widgets_qstatusbar.cpp 0
By default QStatusBar provides a QSizeGrip in the lower-right
corner. You can disable it using the setSizeGripEnabled()
\row \li \a{i} > 0 \li \l forward() history
\endtable
- \snippet doc/src/snippets/code/src_gui_widgets_qtextbrowser.cpp 0
+ \snippet code/src_gui_widgets_qtextbrowser.cpp 0
\since 4.4
*/
For example, to allow the user to drag and drop an image onto a QTextEdit,
you could the implement these functions in the following way:
- \snippet doc/src/snippets/textdocument-imagedrop/textedit.cpp 0
+ \snippet textdocument-imagedrop/textedit.cpp 0
We add support for image MIME types by returning true. For all other
MIME types, we use the default implementation.
- \snippet doc/src/snippets/textdocument-imagedrop/textedit.cpp 1
+ \snippet textdocument-imagedrop/textedit.cpp 1
We unpack the image from the QVariant held by the MIME source and insert
it into the document as a resource.
Information about the event is passed in the \a event object.
- \snippet doc/src/snippets/code/src_gui_widgets_qtextedit.cpp 0
+ \snippet code/src_gui_widgets_qtextedit.cpp 0
*/
void QTextEdit::contextMenuEvent(QContextMenuEvent *e)
{
It is equivalent to
- \snippet doc/src/snippets/code/src_gui_widgets_qtextedit.cpp 1
+ \snippet code/src_gui_widgets_qtextedit.cpp 1
*/
void QTextEdit::insertPlainText(const QString &text)
{
It is equivalent to:
- \snippet doc/src/snippets/code/src_gui_widgets_qtextedit.cpp 2
+ \snippet code/src_gui_widgets_qtextedit.cpp 2
\note When using this function with a style sheet, the style sheet will
only apply to the current block in the document. In order to apply a style
#endif
/*! \property QTextEdit::tabChangesFocus
- \brief whether \gui Tab changes focus or is accepted as input
+ \brief whether \uicontrol Tab changes focus or is accepted as input
In some occasions text edits should not allow the user to input
- tabulators or change indentation using the \gui Tab key, as this breaks
+ tabulators or change indentation using the \uicontrol Tab key, as this breaks
the focus chain. The default is false.
*/