diff options
Diffstat (limited to 'src/quickcontrols/doc/src/qtquickcontrols-customize.qdoc')
-rw-r--r-- | src/quickcontrols/doc/src/qtquickcontrols-customize.qdoc | 132 |
1 files changed, 71 insertions, 61 deletions
diff --git a/src/quickcontrols/doc/src/qtquickcontrols-customize.qdoc b/src/quickcontrols/doc/src/qtquickcontrols-customize.qdoc index 19a2619164..1f12b72822 100644 --- a/src/quickcontrols/doc/src/qtquickcontrols-customize.qdoc +++ b/src/quickcontrols/doc/src/qtquickcontrols-customize.qdoc @@ -183,27 +183,58 @@ \section2 Style-specific C++ Extensions - Sometimes you may need to use C++ to extend your custom style. There are two - ways to expose such types to QML: + Sometimes you may need to use C++ to extend your custom style. \list - \li If the style that uses the type is the only style used by an application, - it's enough to register it with the QML engine via qmlRegisterType(): + \li If the style that uses the type is the only style used by an + application, register the type with the QML engine by adding the QML_ELEMENT + macro and making the file part of your QML module: + \br + \br + + \if defined(onlinedocs) + \tab {expose-cpp-to-qml}{tab-cmake}{CMake}{checked} + \tab {expose-cpp-to-qml}{tab-qmake}{qmake}{} + \tabcontent {tab-cmake} + \else + \section3 Using CMake + \endif + \badcode + qt_add_qml_module(ACoolItem + URI MyItems + VERSION 1.0 + SOURCES + acoolcppitem.cpp acoolcppitem.h + ) + \endcode + \if defined(onlinedocs) + \endtabcontent + \tabcontent {tab-qmake} + \else + \section3 Using QMake + \endif + \code + CONFIG += qmltypes + QML_IMPORT_NAME = MyItems + QML_IMPORT_MAJOR_VERSION = 1 + \endcode + + If the header the class is declared in is not accessible from your + project's include path, you may have to amend the include path so + that the generated registration code can be compiled. \code - qmlRegisterType<ACoolCppItem>("MyApp", 1, 0, "ACoolItem"); + INCLUDEPATH += MyItems \endcode + \if defined(onlinedocs) + \endtabcontent + \endif - See \l {Using C++ Data From QML} for more information about this. + See \l {Defining QML Types from C++} and \l {Building a QML application} + for more information. \li If the style that uses the type is one of many styles used by an - application, it may be better to only register it when necessary. This - is the point at which it would make sense to implement your own - \l {Creating C++ Plugins for QML}{QML plugin}. - - Using a plugin as part of your style is not that much different from - using a set of QML files. The only difference is that the plugin and - its \c qmldir file must be present in the same directory as the QML - files. + application, consider putting each style into a separate module. The + modules will then be loaded on demand. \endlist \section3 Considerations for custom styles @@ -433,9 +464,9 @@ Next, we add a drop shadow to the \l {Control::}{background} delegate of the Button: - \code + \qml // ... - import QtGraphicalEffects + import QtQuick.Effects import MyStyle // ... @@ -443,14 +474,15 @@ // ... layer.enabled: control.enabled && control.MyStyle.elevation > 0 - layer.effect: DropShadow { - verticalOffset: 1 - color: control.visualFocus ? "#330066ff" : "#aaaaaa" - samples: control.MyStyle.elevation - spread: 0.5 + layer.effect: MultiEffect { + shadowEnabled: true + shadowHorizontalOffset: 3 + shadowVerticalOffset: 3 + shadowColor: control.visualFocus ? "#330066ff" : "#aaaaaa" + shadowBlur: control.pressed ? 0.8 : 0.4 } } - \endcode + \endqml Note that we: @@ -525,7 +557,7 @@ \code import QtQuick - import QtQuick.Controls + import QtQuick.Controls.Basic ApplicationWindow { visible: true @@ -590,46 +622,21 @@ \snippet qtquickcontrols-combobox-custom.qml file As explained in \l {ComboBox Model Roles}, ComboBox supports multiple - types of models. If you know that your ComboBox instances will only - ever use one particular type of model, then it is possible to simplify - the code above. + types of models. - For example, if your models will only ever be derived from - \l QAbstractItemModel and have more than one role, the following - binding is sufficient: + Since \l {qml-data-models}{all the models provide an anonymous property} + with \c modelData, the following expression retrieves the right text in + all cases: \code text: model[control.textRole] \endcode - However, if you want to support all standard models, the more complex - binding is necessary, and is explained in detail below. - - \quotefromfile qtquickcontrols-combobox-custom.qml - \skipto control.textRole - \printto Array.isArray - - The first line checks if the \l {ComboBox::}{textRole} property has - been set. It is only necessary to set this property if the model - has more than one role. - - \printline Array.isArray - - If \c textRole has been set, the next step is to check if the model - is an array. - - If it is an array, the \c modelData context property will be available, - and so it must be used. Square bracket notation is used to access - the property of modelData since the property name is not known ahead - of time. - - If it is not an array, the \c model context property must be used - instead. - - \printline modelData - - Finally, if \c textRole has not been set, then the model only has one - role, and so it is sufficient to use the value of \c modelData. + When you provide a specific \c textRole and a model with structured + data that provides the selected role, this is expression is a regular + property lookup. When you provide a model with singular data, such as + a list of strings, and an empty \c textRole, this expression retrieves + the \c modelData. \section2 Customizing DelayButton @@ -721,7 +728,7 @@ \quotefromfile qtquickcontrols-menu-custom.qml \skipto import QtQuick - \printuntil import QtQuick.Controls + \printuntil import QtQuick.Controls.Basic \skipto Menu \printto eof @@ -736,7 +743,7 @@ \quotefromfile qtquickcontrols-menubar-custom.qml \skipto import QtQuick - \printuntil import QtQuick.Controls + \printuntil import QtQuick.Controls.Basic \skipto MenuBar \printto eof @@ -768,7 +775,7 @@ \quotefromfile qtquickcontrols-popup-custom.qml \skipto import QtQuick - \printuntil import QtQuick.Controls + \printuntil import QtQuick.Controls.Basic \codeline \skipto Popup \printuntil { @@ -786,6 +793,9 @@ \snippet qtquickcontrols-progressbar-custom.qml file + Above, the content item is also animated to represent an + \l {ProgressBar::}{indeterminate} progress bar state. + \section2 Customizing RadioButton @@ -1003,7 +1013,7 @@ \quotefromfile qtquickcontrols-tooltip-custom.qml \skipto import QtQuick - \printuntil import QtQuick.Controls + \printuntil import QtQuick.Controls.Basic \skipto ToolTip \printuntil } \printuntil } |