QStringList args;
args << QLatin1String("-collectionFile")
<< QLibraryInfo::location(QLibraryInfo::ExamplesPath)
- + QLatin1String("/help/simpletextviewer/documentation/simpletextviewer.qhc")
+ + QLatin1String("/qtassistant/simpletextviewer/documentation/simpletextviewer.qhc")
<< QLatin1String("-enableRemoteControl");
proc->start(app, args);
****************************************************************************/
/*!
- \example help/simpletextviewer
+ \example simpletextviewer
\title Simple Text Viewer Example
\brief The Simple Text Viewer example shows how to use \QA as a customized
// ![0]
textViewer = new TextEdit;
textViewer->setContents(QLibraryInfo::location(QLibraryInfo::ExamplesPath)
- + QLatin1String("/help/simpletextviewer/documentation/intro.html"));
+ + QLatin1String("/qtassistant/simpletextviewer/documentation/intro.html"));
setCentralWidget(textViewer);
createActions();
QT += widgets
-target.path = $$[QT_INSTALL_EXAMPLES]/help/simpletextviewer
+target.path = $$[QT_INSTALL_EXAMPLES]/qtassistant/simpletextviewer
INSTALLS += target
****************************************************************************/
/*!
- \example designer/arthurplugin
+ \example arthurplugin
\title Arthur Plugin
\brief In this example we demonstrate the abilities of Qt's painting system
****************************************************************************/
/*!
- \example designer/calculatorbuilder
+ \example calculatorbuilder
\title Calculator Builder Example
\brief The Calculator Builder example shows how to create a user interface from
\image calculatorbuilder-example.png
- We use the form created in the \l{designer/calculatorform}{Calculator Form}
+ We use the form created in the \l{calculatorform}{Calculator Form}
example to show that the same user interface can be generated when the
application is executed or defined when the application is built.
\section1 Preparation
- The \l{designer/calculatorform}{Calculator Form} example defines a user
+ The \l{calculatorform}{Calculator Form} example defines a user
interface that we can use without modification. In this example, we use a
\l{The Qt Resource System}{resource file} to contain the \c{calculatorform.ui}
file created in the previous example, but it could be stored on disk instead.
\c QtUiTools module library. The project file we use contains all the
necessary information to do this:
- \snippet designer/calculatorbuilder/calculatorbuilder.pro 0
+ \snippet calculatorbuilder/calculatorbuilder.pro 0
All the other necessary files are declared as usual.
The \c CalculatorForm class defines the widget used to host the form's
user interface:
- \snippet designer/calculatorbuilder/calculatorform.h 0
+ \snippet calculatorbuilder/calculatorform.h 0
Note that we do not need to include a header file to describe the user
interface. We only define two public slots, using the auto-connection
\c libQtUiTools library, so we first ensure that we include the header
file for the module:
- \snippet designer/calculatorbuilder/calculatorform.cpp 0
+ \snippet calculatorbuilder/calculatorform.cpp 0
The constructor uses a form loader object to construct the user
interface that we retrieve, via a QFile object, from the example's
resources:
- \snippet designer/calculatorbuilder/calculatorform.cpp 1
+ \snippet calculatorbuilder/calculatorform.cpp 1
By including the user interface in the example's resources, we ensure
that it will be present when the example is run. The \c{loader.load()}
and we record them for later use. The \c qFindChild() template function
allows us to query widgets in order to find named child widgets.
- \snippet designer/calculatorbuilder/calculatorform.cpp 2
+ \snippet calculatorbuilder/calculatorform.cpp 2
The widgets created by the form loader need to be connected to the
specially-named slots in the \c CalculatorForm object. We use Qt's
meta-object system to enable these connections:
- \snippet designer/calculatorbuilder/calculatorform.cpp 3
+ \snippet calculatorbuilder/calculatorform.cpp 3
The form widget is added to a layout, and the window title is set:
- \snippet designer/calculatorbuilder/calculatorform.cpp 4
+ \snippet calculatorbuilder/calculatorform.cpp 4
The two slots that modify widgets provided by the form are defined
- in a similar way to those in the \l{designer/calculatorform}{Calculator
+ in a similar way to those in the \l{calculatorform}{Calculator
Form} example, except that we read the values from the spin boxes and
write the result to the output widget via the pointers we recorded in
the constructor:
- \snippet designer/calculatorbuilder/calculatorform.cpp 5
+ \snippet calculatorbuilder/calculatorform.cpp 5
\codeline
- \snippet designer/calculatorbuilder/calculatorform.cpp 7
+ \snippet calculatorbuilder/calculatorform.cpp 7
The advantage of this approach is that we can replace the form when the
application is run, but we can still manipulate the widgets it contains
****************************************************************************/
/*!
- \example designer/calculatorform
+ \example calculatorform
\title Calculator Form Example
\brief The Calculator Form Example shows how to use a form created with
To ensure that the example can use this file, we need to include a \c FORMS
declaration in the example's project file:
- \snippet designer/calculatorform/calculatorform.pro 1
+ \snippet calculatorform/calculatorform.pro 1
When the project is built, \c uic will create a header file that lets us
construct the form.
to include the \c ui_calculatorform.h header file created by \c uic
during the build process:
- \snippet designer/calculatorform/calculatorform.h 0
+ \snippet calculatorform/calculatorform.h 0
We define the \c CalculatorForm class by subclassing QWidget because the
form itself is based on QWidget:
- \snippet designer/calculatorform/calculatorform.h 1
+ \snippet calculatorform/calculatorform.h 1
Apart from the constructor, the class contains two private slots that
are named according to the auto-connection naming convention required
The constructor simply calls the base class's constructor and
sets up the form's user interface.
- \snippet designer/calculatorform/calculatorform.cpp 0
+ \snippet calculatorform/calculatorform.cpp 0
The user interface is set up with the \c setupUI() function. We pass
\c this as the argument to this function to use the \c CalculatorForm
"inputSpinBox1" in the user interface emits the
\l{QSpinBox::valueChanged()}{valueChanged()} signal:
- \snippet designer/calculatorform/calculatorform.cpp 1
+ \snippet calculatorform/calculatorform.cpp 1
When this occurs, we use the value supplied by the signal to update the
output label by setting its new text directly. We access the output label
"inputSpinBox2", emits the \l{QSpinBox::valueChanged()}{valueChanged()}
signal:
- \snippet designer/calculatorform/calculatorform.cpp 2
+ \snippet calculatorform/calculatorform.cpp 2
In this case, the value from the first spin box is read and combined
with the value supplied by the signal. Again, the output label is
****************************************************************************/
/*!
- \example designer/containerextension
+ \example containerextension
\title Container Extension Example
\brief The Container Extension example shows how to create a custom
The project file must contain some additional information to
ensure that the plugin will work as expected:
- \snippet designer/containerextension/containerextension.pro 0
- \snippet designer/containerextension/containerextension.pro 1
+ \snippet containerextension/containerextension.pro 0
+ \snippet containerextension/containerextension.pro 1
The \c TEMPLATE variable's value makes \c qmake create the custom
widget as a library. Later, we will ensure that the widget will be
The header and source files for the widget are declared in the
usual way:
- \snippet designer/containerextension/containerextension.pro 2
+ \snippet containerextension/containerextension.pro 2
We provide an implementation of the plugin interface so that \QD
can use the custom widget. In this particular example we also
target path for the project and adding it to the list of items to
install:
- \snippet designer/doc/snippets/doc_src_examples_containerextension.pro 0
+ \snippet doc/snippets/doc_src_examples_containerextension.pro 0
The container extension is created as a library, and will be
installed alongside the other \QD plugins when the project is
The \c MultiPageWidgetPlugin class exposes the \c MultiPageWidget
class to \QD. Its definition is similar to the \l
- {designer/customwidgetplugin}{Custom Widget Plugin} example's
+ {customwidgetplugin}{Custom Widget Plugin} example's
plugin class which is explained in detail. The parts of the class
definition that is specific to this particular custom widget is
the class name and a couple of private slots:
- \snippet designer/containerextension/multipagewidgetplugin.h 0
+ \snippet containerextension/multipagewidgetplugin.h 0
The plugin class provides \QD with basic information about our
plugin, such as its class name and its include file. Furthermore
each page their own title, we have chosen to use the
QWidget::windowTitle property to store the page title (for more
information see the MultiPageWidget class \l
- {designer/containerextension/multipagewidget.cpp}{implementation}). Note
+ {containerextension/multipagewidget.cpp}{implementation}). Note
that currently there is no way of adding a custom property (e.g.,
a page title) to the pages without using a predefined property as
placeholder.
\section1 MultiPageWidgetPlugin Class Implementation
The MultiPageWidgetPlugin class implementation is in most parts
- equivalent to the \l {designer/customwidgetplugin}{Custom Widget
+ equivalent to the \l {customwidgetplugin}{Custom Widget
Plugin} example's plugin class:
- \snippet designer/containerextension/multipagewidgetplugin.cpp 0
+ \snippet containerextension/multipagewidgetplugin.cpp 0
\codeline
- \snippet designer/containerextension/multipagewidgetplugin.cpp 3
+ \snippet containerextension/multipagewidgetplugin.cpp 3
One of the functions that differ is the isContainer() function
which returns true in this example since our custom widget is
intended to be used as a container.
- \snippet designer/containerextension/multipagewidgetplugin.cpp 1
+ \snippet containerextension/multipagewidgetplugin.cpp 1
Another function that differ is the function creating our custom widget:
- \snippet designer/containerextension/multipagewidgetplugin.cpp 2
+ \snippet containerextension/multipagewidgetplugin.cpp 2
In addition to create and return the widget, we connect our custom
container widget's currentIndexChanged() signal to the plugin's
widget's currentIndexChanged() \e signal is emitted, i.e. whenever
the user views another page:
- \snippet designer/containerextension/multipagewidgetplugin.cpp 8
+ \snippet containerextension/multipagewidgetplugin.cpp 8
First, we retrieve the object emitting the signal using the
QObject::sender() and qobject_cast() functions. If it's called in
a slot activated by a signal, QObject::sender() returns a pointer
to the object that sent the signal; otherwise it returns 0.
- \snippet designer/containerextension/multipagewidgetplugin.cpp 9
+ \snippet containerextension/multipagewidgetplugin.cpp 9
Once we have the widget we can update the property editor. \QD
uses the QDesignerPropertySheetExtension class to feed its
get hold of the extension we must first retrieve access to \QD's
extension manager:
- \snippet designer/containerextension/multipagewidgetplugin.cpp 10
- \snippet designer/containerextension/multipagewidgetplugin.cpp 11
+ \snippet containerextension/multipagewidgetplugin.cpp 10
+ \snippet containerextension/multipagewidgetplugin.cpp 11
Again we first retrieve the widget emitting the signal, using the
QObject::sender() and qobject_cast() functions. Then we retrieve
use the static QDesignerFormWindowInterface::findFormWindow()
function to retrieve the form containing our widget.
- \snippet designer/containerextension/multipagewidgetplugin.cpp 12
+ \snippet containerextension/multipagewidgetplugin.cpp 12
Now that we have the form window, the QDesignerFormWindowInterface
class provides the \l
QDesignerFormEditorInterface::extensionManager() function returns
a reference to the current extension manager.
- \snippet designer/containerextension/multipagewidgetplugin.cpp 13
+ \snippet containerextension/multipagewidgetplugin.cpp 13
Once we have the extension manager we can update the extension
sheet: First we retrieve the property extension for the page which
mentioned, we have chosen to use the QWidget::windowTitle property
to store the page title (for more information see the
MultiPageWidget class \l
- {designer/containerextension/multipagewidget.cpp}{implementation}).
+ {containerextension/multipagewidget.cpp}{implementation}).
Finally, we implicitly force an update of the page's property
sheet by calling the
QDesignerPropertySheetExtension::setChanged() function.
- \snippet designer/containerextension/multipagewidgetplugin.cpp 4
+ \snippet containerextension/multipagewidgetplugin.cpp 4
Note also the initialize() function: The \c initialize() function
takes a QDesignerFormEditorInterface object as argument.
- \snippet designer/containerextension/multipagewidgetplugin.cpp 5
+ \snippet containerextension/multipagewidgetplugin.cpp 5
When creating extensions associated with custom widget plugins, we
need to access \QD's current extension manager which we retrieve
not created until \QD must know whether the associated widget is a
container, or not.
- \snippet designer/containerextension/multipagewidgetplugin.cpp 6
+ \snippet containerextension/multipagewidgetplugin.cpp 6
We create a \c MultiPageWidgetExtensionFactory object that we
register using \QD's current \l {QExtensionManager}{extension
create a container extension for that widget. This factory will in
turn create a \c MultiPageWidgetExtension object.
- \snippet designer/containerextension/multipagewidgetplugin.cpp 7
+ \snippet containerextension/multipagewidgetplugin.cpp 7
Finally, take a look at the \c domXml() function. This function
includes default settings for the widget in the standard XML
page; any inital pages of a multi-page widget must be specified
within this function.
- \snippet designer/containerextension/multipagewidgetplugin.cpp 14
+ \snippet containerextension/multipagewidgetplugin.cpp 14
Remember to use the Q_EXPORT_PLUGIN2() macro to export the
MultiPageWidgetPlugin class for use with Qt's plugin handling
The \c MultiPageWidgetExtensionFactory class inherits QExtensionFactory
which provides a standard extension factory for \QD.
- \snippet designer/containerextension/multipagewidgetextensionfactory.h 0
+ \snippet containerextension/multipagewidgetextensionfactory.h 0
The subclass's purpose is to reimplement the
QExtensionFactory::createExtension() function, making it able to
The class constructor simply calls the QExtensionFactory base
class constructor:
- \snippet designer/containerextension/multipagewidgetextensionfactory.cpp 0
+ \snippet containerextension/multipagewidgetextensionfactory.cpp 0
As described above, the factory is invoked when \QD must know
whether the associated widget is a container, or not.
- \snippet designer/containerextension/multipagewidgetextensionfactory.cpp 1
+ \snippet containerextension/multipagewidgetextensionfactory.cpp 1
\QD's behavior is the same whether the requested extension is
associated with a container, a member sheet, a property sheet or a
QDesignerContainerExtension which allows you to add (and delete)
pages to a multi-page container plugin in \QD.
- \snippet designer/containerextension/multipagewidgetcontainerextension.h 0
+ \snippet containerextension/multipagewidgetcontainerextension.h 0
It is important to recognize that the QDesignerContainerExtension
class only is intended to provide \QD access to your custom
extension. We will need this later to access the custom multi-page
widget performing the requested actions.
- \snippet designer/containerextension/multipagewidgetcontainerextension.cpp 0
+ \snippet containerextension/multipagewidgetcontainerextension.cpp 0
To fully enable \QD to manage and manipulate your custom
multi-page widget, you must reimplement all the functions of
QDesignerContainerExtension:
- \snippet designer/containerextension/multipagewidgetcontainerextension.cpp 1
+ \snippet containerextension/multipagewidgetcontainerextension.cpp 1
\codeline
- \snippet designer/containerextension/multipagewidgetcontainerextension.cpp 2
+ \snippet containerextension/multipagewidgetcontainerextension.cpp 2
\codeline
- \snippet designer/containerextension/multipagewidgetcontainerextension.cpp 3
+ \snippet containerextension/multipagewidgetcontainerextension.cpp 3
You must reimplement \l
{QDesignerContainerExtension::addWidget()}{addWidget()} adding a
{QDesignerContainerExtension::currentIndex()}{currentIndex()}
returning the index of the currently selected page.
- \snippet designer/containerextension/multipagewidgetcontainerextension.cpp 4
+ \snippet containerextension/multipagewidgetcontainerextension.cpp 4
\codeline
- \snippet designer/containerextension/multipagewidgetcontainerextension.cpp 5
+ \snippet containerextension/multipagewidgetcontainerextension.cpp 5
\codeline
- \snippet designer/containerextension/multipagewidgetcontainerextension.cpp 6
+ \snippet containerextension/multipagewidgetcontainerextension.cpp 6
\codeline
- \snippet designer/containerextension/multipagewidgetcontainerextension.cpp 7
+ \snippet containerextension/multipagewidgetcontainerextension.cpp 7
You must reimplement \l
{QDesignerContainerExtension::insertWidget()}{insertWidget()}
the user manipulate and populate its pages, and navigate among
these using a combobox.
- \snippet designer/containerextension/multipagewidget.h 0
+ \snippet containerextension/multipagewidget.h 0
The main detail to observe is that your custom multi-page widget
must implement functionality corresponding to the
page titles.
See the MultiPageWidget class \l
- {designer/containerextension/multipagewidget.cpp}{implementation}
+ {containerextension/multipagewidget.cpp}{implementation}
for more details.
*/
****************************************************************************/
/*!
- \example designer/customwidgetplugin
+ \example customwidgetplugin
\title Custom Widget Plugin Example
\brief The Custom Widget example shows how to create a custom widget plugin for \QD.
project file that we use needs to contain information about \QD's
library components:
- \snippet designer/customwidgetplugin/customwidgetplugin.pro 2
- \snippet designer/customwidgetplugin/customwidgetplugin.pro 0
+ \snippet customwidgetplugin/customwidgetplugin.pro 2
+ \snippet customwidgetplugin/customwidgetplugin.pro 0
The \c TEMPLATE variable's value makes \c qmake create the custom
widget as a library. Later, we will ensure that the widget will be
and we provide an implementation of the plugin interface so that \QD can
use the custom widget:
- \snippet designer/customwidgetplugin/customwidgetplugin.pro 3
+ \snippet customwidgetplugin/customwidgetplugin.pro 3
It is also important to ensure that the plugin is installed in a
location that is searched by \QD. We do this by specifying a
target path for the project and adding it to the list of items to
install:
- \snippet designer/doc/snippets/doc_src_examples_customwidgetplugin.pro 0
+ \snippet doc/snippets/doc_src_examples_customwidgetplugin.pro 0
The custom widget is created as a library, and will be installed
alongside the other \QD plugins when the project is installed
the QDesignerCustomWidgetInterface class, and implements an
interface defined by QDesignerCustomWidgetInterface:
- \snippet designer/customwidgetplugin/customwidgetplugin.h 0
+ \snippet customwidgetplugin/customwidgetplugin.h 0
The functions provide information about the widget that \QD can use in
the \l{Getting to Know Qt Designer#WidgetBox}{widget box}.
The class constructor simply calls the QObject base class constructor
and sets the \c initialized variable to \c false.
- \snippet designer/customwidgetplugin/customwidgetplugin.cpp 0
+ \snippet customwidgetplugin/customwidgetplugin.cpp 0
\QD will initialize the plugin when it is required by calling the
\c initialize() function:
- \snippet designer/customwidgetplugin/customwidgetplugin.cpp 1
+ \snippet customwidgetplugin/customwidgetplugin.cpp 1
In this example, the \c initialized private variable is tested, and only
set to \c true if the plugin is not already initialized. Although, this
The \c isInitialized() function lets \QD know whether the plugin is
ready for use:
- \snippet designer/customwidgetplugin/customwidgetplugin.cpp 2
+ \snippet customwidgetplugin/customwidgetplugin.cpp 2
Instances of the custom widget are supplied by the \c createWidget()
function. The implementation for the analog clock is straightforward:
- \snippet designer/customwidgetplugin/customwidgetplugin.cpp 3
+ \snippet customwidgetplugin/customwidgetplugin.cpp 3
In this case, the custom widget only requires a \c parent to be specified.
If other arguments need to be supplied to the widget, they can be
The \c name() function returns the name of class that provides the
custom widget:
- \snippet designer/customwidgetplugin/customwidgetplugin.cpp 4
+ \snippet customwidgetplugin/customwidgetplugin.cpp 4
The \c group() function is used to describe the type of widget that the
custom widget belongs to:
- \snippet designer/customwidgetplugin/customwidgetplugin.cpp 5
+ \snippet customwidgetplugin/customwidgetplugin.cpp 5
The widget plugin will be placed in a section identified by its
group name in \QD's widget box. The icon used to represent the
widget in the widget box is returned by the \c icon() function:
- \snippet designer/customwidgetplugin/customwidgetplugin.cpp 6
+ \snippet customwidgetplugin/customwidgetplugin.cpp 6
In this case, we return a null icon to indicate that we have no icon
that can be used to represent the widget.
entry in the widget box. The \c toolTip() function should return a short
message describing the widget:
- \snippet designer/customwidgetplugin/customwidgetplugin.cpp 7
+ \snippet customwidgetplugin/customwidgetplugin.cpp 7
The \c whatsThis() function can return a longer description:
- \snippet designer/customwidgetplugin/customwidgetplugin.cpp 8
+ \snippet customwidgetplugin/customwidgetplugin.cpp 8
The \c isContainer() function tells \QD whether the widget is supposed to
be used as a container for other widgets. If not, \QD will not allow the
user to place widgets inside it.
- \snippet designer/customwidgetplugin/customwidgetplugin.cpp 9
+ \snippet customwidgetplugin/customwidgetplugin.cpp 9
Most widgets in Qt can contain child widgets, but it only makes sense
to use dedicated container widgets for this purpose in \QD. By returning
the widget in the standard XML format used by \QD. In this case, we only
specify the widget's geometry:
- \snippet designer/customwidgetplugin/customwidgetplugin.cpp 10
+ \snippet customwidgetplugin/customwidgetplugin.cpp 10
If the widget provides a reasonable size hint, it is not necessary to
define it here. In addition, returning an empty string instead of a
the \c includeFile() function to return the name of the header file
containing the custom widget class definition:
- \snippet designer/customwidgetplugin/customwidgetplugin.cpp 12
+ \snippet customwidgetplugin/customwidgetplugin.cpp 12
*/
****************************************************************************/
/*!
- \example designer/taskmenuextension
+ \example taskmenuextension
\title Task Menu Extension Example
\brief The Task Menu Extension example shows how to create a custom
The project file must contain some additional information to
ensure that the plugin will work as expected:
- \snippet designer/taskmenuextension/taskmenuextension.pro 0
- \snippet designer/taskmenuextension/taskmenuextension.pro 1
+ \snippet taskmenuextension/taskmenuextension.pro 0
+ \snippet taskmenuextension/taskmenuextension.pro 1
The \c TEMPLATE variable's value makes \c qmake create the custom
widget as a library. Later, we will ensure that the widget will be
The header and source files for the widget are declared in the
usual way:
- \snippet designer/taskmenuextension/taskmenuextension.pro 2
+ \snippet taskmenuextension/taskmenuextension.pro 2
We provide an implementation of the plugin interface so that \QD
can use the custom widget. In this particular example we also
target path for the project and adding it to the list of items to
install:
- \snippet designer/doc/snippets/doc_src_examples_taskmenuextension.pro 0
+ \snippet doc/snippets/doc_src_examples_taskmenuextension.pro 0
The task menu extension is created as a library, and will be
installed alongside the other \QD plugins when the project is
The \c TicTacToePlugin class exposes \c the TicTacToe class to
\QD. Its definition is equivalent to the \l
- {designer/customwidgetplugin}{Custom Widget Plugin} example's
+ {customwidgetplugin}{Custom Widget Plugin} example's
plugin class which is explained in detail. The only part of the
class definition that is specific to this particular custom widget
is the class name:
- \snippet designer/taskmenuextension/tictactoeplugin.h 0
+ \snippet taskmenuextension/tictactoeplugin.h 0
The plugin class provides \QD with basic information about our
plugin, such as its class name and its include file. Furthermore
\section1 TicTacToePlugin Class Implementation
The TicTacToePlugin class implementation is in most parts
- equivalent to the \l {designer/customwidgetplugin}{Custom Widget
+ equivalent to the \l {customwidgetplugin}{Custom Widget
Plugin} example's plugin class:
- \snippet designer/taskmenuextension/tictactoeplugin.cpp 0
+ \snippet taskmenuextension/tictactoeplugin.cpp 0
The only function that differs significantly is the initialize()
function:
- \snippet designer/taskmenuextension/tictactoeplugin.cpp 1
+ \snippet taskmenuextension/tictactoeplugin.cpp 1
The \c initialize() function takes a QDesignerFormEditorInterface
object as argument. The QDesignerFormEditorInterface class
editor and the widget box. Custom widget plugins have access to
the same components.
- \snippet designer/taskmenuextension/tictactoeplugin.cpp 2
+ \snippet taskmenuextension/tictactoeplugin.cpp 2
When creating extensions associated with custom widget plugins, we
need to access \QD's current extension manager which we retrieve
required. So, in this example, the task menu extension itself is
not created until a task menu is requested by the user.
- \snippet designer/taskmenuextension/tictactoeplugin.cpp 3
+ \snippet taskmenuextension/tictactoeplugin.cpp 3
We create a \c TicTacToeTaskMenuFactory object that we register
using \QD's current \l {QExtensionManager}{extension manager}
default settings for the widget in the standard XML format used by
Qt Designer), since no default values are necessary.
- \snippet designer/taskmenuextension/tictactoeplugin.cpp 4
+ \snippet taskmenuextension/tictactoeplugin.cpp 4
Finally, we use the Q_EXPORT_PLUGIN2() macro to export the
TicTacToePlugin class for use with Qt's plugin handling classes:
The \c TicTacToeTaskMenuFactory class inherits QExtensionFactory
which provides a standard extension factory for \QD.
- \snippet designer/taskmenuextension/tictactoetaskmenu.h 1
+ \snippet taskmenuextension/tictactoetaskmenu.h 1
The subclass's purpose is to reimplement the
QExtensionFactory::createExtension() function, making it able to
The class constructor simply calls the QExtensionFactory base
class constructor:
- \snippet designer/taskmenuextension/tictactoetaskmenu.cpp 4
+ \snippet taskmenuextension/tictactoetaskmenu.cpp 4
As described above, the factory is invoked when the user request a
task menu by clicking the right mouse button over a widget with
extension factories calling \c createExtension() for each until
one responds by creating the requested extension.
- \snippet designer/taskmenuextension/tictactoetaskmenu.cpp 5
+ \snippet taskmenuextension/tictactoetaskmenu.cpp 5
So the first thing we do in \c
TicTacToeTaskMenuFactory::createExtension() is to check if the
which allows you to add custom entries (in the form of QActions)
to the task menu in \QD.
- \snippet designer/taskmenuextension/tictactoetaskmenu.h 0
+ \snippet taskmenuextension/tictactoetaskmenu.h 0
We reimplement the \c preferredEditAction() and \c taskActions()
functions. Note that we implement a constructor that takes \e two
\section1 TicTacToeTaskMenu Class Implementation
- \snippet designer/taskmenuextension/tictactoetaskmenu.cpp 0
+ \snippet taskmenuextension/tictactoetaskmenu.cpp 0
In the constructor we first save the reference to the \c TicTacToe
widget sent as parameter, i.e the widget which state we want to
invoked. We also create our custom \c editStateAction and connect
it to the \c editState() slot.
- \snippet designer/taskmenuextension/tictactoetaskmenu.cpp 1
+ \snippet taskmenuextension/tictactoetaskmenu.cpp 1
The \c editState() slot is called whenever the user chooses the
\gui {Edit State...} option in a \c TicTacToe widget's task menu. The
the widget, and allowing the user to edit its state by playing the
game.
- \snippet designer/taskmenuextension/tictactoetaskmenu.cpp 2
+ \snippet taskmenuextension/tictactoetaskmenu.cpp 2
We reimplement the \c preferredEditAction() function to return our
custom \c editStateAction as the action that should be invoked
when selecting a \c TicTacToe widget and pressing \key F2 .
- \snippet designer/taskmenuextension/tictactoetaskmenu.cpp 3
+ \snippet taskmenuextension/tictactoetaskmenu.cpp 3
We reimplement the \c taskActions() function to return a list of
our custom actions making these appear on top of the default menu
user modify the state of the currently selected Tic-Tac-Toe
plugin.
- \snippet designer/taskmenuextension/tictactoedialog.h 0
+ \snippet taskmenuextension/tictactoedialog.h 0
We reimplement the \c sizeHint() function. We also declare two
private slots: \c resetState() and \c saveState(). In addition to
\section1 TicTacToeDialog Class Implementation
- \snippet designer/taskmenuextension/tictactoedialog.cpp 0
+ \snippet taskmenuextension/tictactoedialog.cpp 0
In the constructor we first save the reference to the TicTacToe
widget sent as parameter, i.e the widget which state the user want
Finally, we create the dialog's buttons and layout.
- \snippet designer/taskmenuextension/tictactoedialog.cpp 1
+ \snippet taskmenuextension/tictactoedialog.cpp 1
We reimplement the \c sizeHint() function to ensure that the
dialog is given a reasonable size.
- \snippet designer/taskmenuextension/tictactoedialog.cpp 2
+ \snippet taskmenuextension/tictactoedialog.cpp 2
The \c resetState() slot is called whenever the user press the
\gui Reset button. The only thing we do is to call the \c
clearBoard() function for the editor widget, i.e. the \c TicTacToe
widget we created in the dialog's constructor.
- \snippet designer/taskmenuextension/tictactoedialog.cpp 3
+ \snippet taskmenuextension/tictactoedialog.cpp 3
The \c saveState() slot is called whenever the user press the \gui
OK button, and transfers the state of the editor widget to the
widget, you can use the static
QDesignerFormWindowInterface::findFormWindow() function:
- \snippet designer/taskmenuextension/tictactoedialog.cpp 4
+ \snippet taskmenuextension/tictactoedialog.cpp 4
After retrieving the form window of the widget (which state we
want to modify), we use the QDesignerFormWindowInterface::cursor()
finally set the state property using the
QDesignerFormWindowCursorInterface::setProperty() function.
- \snippet designer/taskmenuextension/tictactoedialog.cpp 5
+ \snippet taskmenuextension/tictactoedialog.cpp 5
In the end we call the QEvent::accept() function which sets the
accept flag of the event object. Setting the \c accept parameter
The \c TicTacToe class is a custom widget that lets the user play
the Tic-Tac-Toe game.
- \snippet designer/taskmenuextension/tictactoe.h 0
+ \snippet taskmenuextension/tictactoe.h 0
The main details to observe in the \c TicTacToe class defintion is
the declaration of the \c state property and its \c state() and \c
****************************************************************************/
/*!
- \example designer/worldtimeclockbuilder
+ \example worldtimeclockbuilder
\title World Time Clock Builder Example
\brief The World Time Clock Builder example shows how forms created with Qt
\image worldtimeclockbuilder-example.png
This example uses a form containing the custom widget plugin described in the
- \l{designer/worldtimeclockplugin}{World Time Clock Plugin} example, and
+ \l{worldtimeclockplugin}{World Time Clock Plugin} example, and
dynamically generates a user interface using the QUiLoader class, part of
the QtUiTools module.
\section1 Preparation
- As with the \l{designer/calculatorbuilder}{Calculator Builder} example, the
+ As with the \l{calculatorbuilder}{Calculator Builder} example, the
project file for this example needs to include the appropriate definitions
to ensure that it is built against the required Qt modules.
- \snippet designer/worldtimeclockbuilder/worldtimeclockbuilder.pro 0
+ \snippet worldtimeclockbuilder/worldtimeclockbuilder.pro 0
By appending \c form to the \c CONFIG declaration, we instruct \c qmake to
generate a dependency on the \c libQtUiTools library containing the QtUiTools
be processed and built into the application. The resource file contains
an entry for the particular form that we wish to use:
- \quotefile designer/worldtimeclockbuilder/worldtimeclockbuilder.qrc
+ \quotefile worldtimeclockbuilder/worldtimeclockbuilder.qrc
Forms do not need to be included with the application in this way. We only
include a form in the application's resources for convenience, and to keep
required to write an application, we must include the appropriate header
file:
- \snippet designer/worldtimeclockbuilder/main.cpp 0
+ \snippet worldtimeclockbuilder/main.cpp 0
The main function initializes the resource system with the Q_INIT_RESOURCE()
macro and constructs an QApplication instance in the usual way:
- \snippet designer/worldtimeclockbuilder/main.cpp 1
+ \snippet worldtimeclockbuilder/main.cpp 1
We construct a QUiLoader object to handle the form we want to use.
defined in the resource file. We use the form loader to load and construct
the form:
- \snippet designer/worldtimeclockbuilder/main.cpp 2
+ \snippet worldtimeclockbuilder/main.cpp 2
Once the form has been loaded, the resource file can be closed and the
widget is shown.
- \snippet designer/worldtimeclockbuilder/main.cpp 3
+ \snippet worldtimeclockbuilder/main.cpp 3
The form loader ensures that all the signal and slot connections between
objects in the form are set up correctly when the form is loaded. As a
****************************************************************************/
/*!
- \example designer/worldtimeclockplugin
+ \example worldtimeclockplugin
\title World Time Clock Plugin Example
\brief The World Time Clock Plugin example shows how to create a custom
\image worldtimeclockplugin-example.png
In this example, we simply extend the \l
- {designer/customwidgetplugin}{Custom Widget Plugin} example and
+ {customwidgetplugin}{Custom Widget Plugin} example and
its custom widget (based on the \l{widgets/analogclock}{Analog
Clock} example), by introducing the concept of signals and slots.
\endlist
First we will take a look at the \c WorldTimeClock class which
- extends the \l {designer/customwidgetplugin}{Custom Widget Plugin}
+ extends the \l {customwidgetplugin}{Custom Widget Plugin}
example's \c AnalogClock class by providing a signal and a
slot. Then we will take a quick look at the \c
WorldTimeClockPlugin class, but this class is in most parts
- identical to the \l {designer/customwidgetplugin}{Custom Widget
+ identical to the \l {customwidgetplugin}{Custom Widget
Plugin} example's implementation.
Finally we take a look at the plugin's project file. The project
file for custom widget plugins needs some additional information
to ensure that they will work within \QD. This is also covered in
- the \l {designer/customwidgetplugin}{Custom Widget Plugin} example,
+ the \l {customwidgetplugin}{Custom Widget Plugin} example,
but due to its importance (custom widget plugins rely on
components supplied with \QD which must be specified in the
project file that we use) we will repeat it here.
The \c WorldTimeClock class inherits QWidget, and is a custom
clock widget with hour and minute hands that is automatically
updated every few seconds. What makes this example different from
- the \l {designer/customwidgetplugin}{Custom Widget Plugin}
+ the \l {customwidgetplugin}{Custom Widget Plugin}
example, is the introduction of the signal and slot in the custom
widget class:
- \snippet designer/worldtimeclockplugin/worldtimeclock.h 1
+ \snippet worldtimeclockplugin/worldtimeclock.h 1
Note the use of the QDESIGNER_WIDGET_EXPORT macro. This is needed
to ensure that \QD can create instances of the widget on some
The \c WorldTimeClockPlugin class exposes the \c WorldTimeClock
class to \QD. Its definition is equivalent to the \l
- {designer/customwidgetplugin}{Custom Widget Plugin} example's
+ {customwidgetplugin}{Custom Widget Plugin} example's
plugin class which is explained in detail. The only part of the
class definition that is specific to this particular custom widget
is the class name:
- \snippet designer/worldtimeclockplugin/worldtimeclockplugin.h 0
+ \snippet worldtimeclockplugin/worldtimeclockplugin.h 0
The plugin class provides \QD with basic information about our
plugin, such as its class name and its include file. Furthermore
The implementation of the \c WorldTimeClockPlugin is also
equivalent to the plugin interface implementation in the \l
- {designer/customwidgetplugin}{Custom Widget Plugin} example (only
+ {customwidgetplugin}{Custom Widget Plugin} example (only
the class name and the implementation of
QDesignerCustomWidgetInterface::domXml() differ). The main thing
to remember is to use the Q_EXPORT_PLUGIN2() macro to export the \c
WorldTimeClockPlugin class for use with \QD:
- \snippet designer/worldtimeclockplugin/worldtimeclockplugin.cpp 0
+ \snippet worldtimeclockplugin/worldtimeclockplugin.cpp 0
Without this macro, there is no way for Qt Designer to use the
widget.
The project file for custom widget plugins needs some additional
information to ensure that they will work as expected within \QD:
- \snippet designer/worldtimeclockplugin/worldtimeclockplugin.pro 0
- \snippet designer/worldtimeclockplugin/worldtimeclockplugin.pro 1
+ \snippet worldtimeclockplugin/worldtimeclockplugin.pro 0
+ \snippet worldtimeclockplugin/worldtimeclockplugin.pro 1
The \c TEMPLATE variable's value make \c qmake create the custom
widget as a library. The \c CONFIG variable contains two values,
usual way, and in addition we provide an implementation of the
plugin interface so that \QD can use the custom widget.
- \snippet designer/worldtimeclockplugin/worldtimeclockplugin.pro 2
+ \snippet worldtimeclockplugin/worldtimeclockplugin.pro 2
It is important to ensure that the plugin is installed in a location that
is searched by \QD. We do this by specifying a target path for the project
and adding it to the list of items to install:
- \snippet designer/doc/snippets/doc_src_examples_worldtimeclockplugin.pro 0
+ \snippet doc/snippets/doc_src_examples_worldtimeclockplugin.pro 0
The custom widget is created as a library, and will be installed
alongside the other \QD plugins when the project is installed
sourcedirs = ..
exampledirs = ../../../../../examples/designer \
+ ../../../../../examples/uitools \
snippets
imagedirs = images
QExtensionManager.
For a complete example creating a custom widget plugin with an
- extension, see the \l {designer/taskmenuextension}{Task Menu
- Extension} or \l {designer/containerextension}{Container
+ extension, see the \l {taskmenuextension}{Task Menu
+ Extension} or \l {containerextension}{Container
Extension} examples.
\section1 Retrieving Access to \QD Components
the QtUiTools module.
For a complete example using QUiLoader, see
- the \l {designer/calculatorbuilder}{Calculator Builder example}.
+ the \l {calculatorbuilder}{Calculator Builder example}.
\sa {Qt Designer Manual}, {QtUiTools Module}
*/
Qt Designer can be compiled into an application or created at run-time.
\list
- \li \l{designer/arthurplugin}{Arthur Plugin}
- \li \l{designer/calculatorbuilder}{Calculator Builder}\raisedaster
- \li \l{designer/calculatorform}{Calculator Form}\raisedaster
- \li \l{designer/customwidgetplugin}{Custom Widget Plugin}\raisedaster
- \li \l{designer/taskmenuextension}{Task Menu Extension}\raisedaster
- \li \l{designer/containerextension}{Container Extension}\raisedaster
- \li \l{designer/worldtimeclockbuilder}{World Time Clock Builder}\raisedaster
- \li \l{designer/worldtimeclockplugin}{World Time Clock Plugin}\raisedaster
+ \li \l{arthurplugin}{Arthur Plugin}
+ \li \l{calculatorbuilder}{Calculator Builder}\raisedaster
+ \li \l{calculatorform}{Calculator Form}\raisedaster
+ \li \l{customwidgetplugin}{Custom Widget Plugin}\raisedaster
+ \li \l{taskmenuextension}{Task Menu Extension}\raisedaster
+ \li \l{containerextension}{Container Extension}\raisedaster
+ \li \l{worldtimeclockbuilder}{World Time Clock Builder}\raisedaster
+ \li \l{worldtimeclockplugin}{World Time Clock Plugin}\raisedaster
\endlist
Examples marked with an asterisk (*) are fully documented.
We will use \c qmake to build the executable, so we need to write a
\c{.pro} file:
- \snippet uitools/calculatorform/calculatorform.pro 0
+ \snippet calculatorform/calculatorform.pro 0
The special feature of this file is the \c FORMS declaration that tells
\c qmake which files to process with \c uic. In this case, the
To use the direct approach, we include the \c ui_calculatorform.h file
directly in \c main.cpp:
- \snippet uitools/calculatorform/main.cpp 0
+ \snippet calculatorform/main.cpp 0
The \c main function creates the calculator widget by constructing a
standard QWidget that we use to host the user interface described by the
\c calculatorform.ui file.
- \snippet uitools/calculatorform/main.cpp 1
+ \snippet calculatorform/main.cpp 1
In this case, the \c{Ui::CalculatorForm} is an interface description object
from the \c ui_calculatorform.h file that sets up all the dialog's widgets
To ensure that we can use the user interface, we need to include the header
file that \c uic generates before referring to \c{Ui::CalculatorForm}:
- \snippet designer/calculatorform/calculatorform.h 0
+ \snippet calculatorform/calculatorform.h 0
This means that the \c{.pro} file must be updated to include
\c{calculatorform.h}:
- \snippet designer/calculatorform/calculatorform.pro 0
+ \snippet calculatorform/calculatorform.pro 0
The subclass is defined in the following way:
- \snippet designer/calculatorform/calculatorform.h 1
+ \snippet calculatorform/calculatorform.h 1
The important feature of the class is the private \c ui object which
provides the code for setting up and managing the user interface.
function. Once this has been done, it is possible to modify the user
interface as needed.
- \snippet designer/calculatorform/calculatorform.cpp 0
+ \snippet calculatorform/calculatorform.cpp 0
We can connect signals and slots in user interface widgets in the usual
way by adding the on_<object name> - prefix. For more information,
We need to include the header file that \c uic generates from the
\c calculatorform.ui file, as follows:
- \snippet uitools/multipleinheritance/calculatorform.h 0
+ \snippet multipleinheritance/calculatorform.h 0
The class is defined in a similar way to the one used in the
\l{The Single Inheritance Approach}{single inheritance approach}, except that
this time we inherit from \e{both} QWidget and \c{Ui::CalculatorForm},
as follows:
- \snippet uitools/multipleinheritance/calculatorform.h 1
+ \snippet multipleinheritance/calculatorform.h 1
We inherit \c{Ui::CalculatorForm} privately to ensure that the user
interface objects are private in our subclass. We can also inherit it with
constructor used in the \l{The Single Inheritance Approach}
{single inheritance} example:
- \snippet uitools/multipleinheritance/calculatorform.cpp 0
+ \snippet multipleinheritance/calculatorform.cpp 0
In this case, the widgets used in the user interface can be accessed in the
same say as a widget created in code by hand. We no longer require the
The QUiLoader::load() function is invoked as shown in this code from the
\l{Text Finder Example}{Text Finder} example:
- \snippet uitools/textfinder/textfinder.cpp 4
+ \snippet textfinder/textfinder.cpp 4
In a class that uses QtUiTools to build its user interface at run time, we
can locate objects in the form using qFindChild(). For example, in the
follownig code, we locate some components based on their object names and
widget types:
- \snippet uitools/textfinder/textfinder.cpp 1
+ \snippet textfinder/textfinder.cpp 1
Processing forms at run-time gives the developer the freedom to change a
program's user interface, just by changing the UI file. This is useful
We use QMetaObject's system to enable signal and slot connections:
- \snippet uitools/textfinder/textfinder.cpp 2
+ \snippet textfinder/textfinder.cpp 2
This enables us to implement the slot, as shown below:
- \snippet uitools/textfinder/textfinder.cpp 6
+ \snippet textfinder/textfinder.cpp 6
\dots
- \snippet uitools/textfinder/textfinder.cpp 8
+ \snippet textfinder/textfinder.cpp 8
Automatic connection of signals and slots provides both a standard naming
convention and an explicit interface for widget designers to work to. By
If the custom widget does not provide a reasonable size hint, it is
necessary to specify a default geometry in the string returned by the
\c domXml() function in your subclass. For example, the
- \c AnalogClockPlugin provided by the \l{designer/customwidgetplugin}
+ \c AnalogClockPlugin provided by the \l{customwidgetplugin}
{Custom Widget Plugin} example, defines a default widgetgeometry in the
following way:
\dots
- \snippet designer/customwidgetplugin/customwidgetplugin.cpp 11
+ \snippet customwidgetplugin/customwidgetplugin.cpp 11
\dots
An additional feature of the \c domXml() function is that, if it returns
with specific plugin support for \QD. This is done with the following
declarations:
- \snippet designer/customwidgetplugin/customwidgetplugin.pro 1
+ \snippet customwidgetplugin/customwidgetplugin.pro 1
If Qt is configured to build in both debug and release modes, \QD will be
built in release mode. When this occurs, it is necessary to ensure that
\section1 Related Examples
For more information on using custom widgets in \QD, refer to the
- \l{designer/customwidgetplugin}{Custom Widget Plugin} and
- \l{designer/worldtimeclockplugin}{World Time Clock Plugin} examples for more
+ \l{customwidgetplugin}{Custom Widget Plugin} and
+ \l{worldtimeclockplugin}{World Time Clock Plugin} examples for more
information about using custom widgets in \QD. Also, you can use the
QDesignerCustomWidgetCollectionInterface class to combine several custom
widgets into a single library.
extension that allows you to add custom menu entries to \QD's task
menu.
- The \l{designer/taskmenuextension}{Task Menu Extension} example
+ The \l{taskmenuextension}{Task Menu Extension} example
illustrates how to use this class.
\row
multi-page container. It provides an extension that allows you to add
and delete pages for a multi-page container plugin in \QD.
- The \l{designer/containerextension}{Container Extension} example
+ The \l{containerextension}{Container Extension} example
further explains how to use this class.
\note It is not possible to add custom per-page properties for some
The purpose is to reimplement the QExtensionFactory::createExtension()
function, making it able to create your extension, such as a
- \l{designer/containerextension}{MultiPageWidget} container extension.
+ \l{containerextension}{MultiPageWidget} container extension.
You can either create a new QExtensionFactory and reimplement the
QExtensionFactory::createExtension() function:
\section1 Related Examples
For more information on creating custom widget extensions in \QD, refer to
- the \l{designer/taskmenuextension}{Task Menu Extension} and
- \l{designer/containerextension}{Container Extension} examples.
+ the \l{taskmenuextension}{Task Menu Extension} and
+ \l{containerextension}{Container Extension} examples.
*/