StylableControls QML Type
Type de base abstrait contenant les types de contrôle pouvant être personnalisés. En savoir plus...
| Import Statement: | import Qt.labs.StyleKit |
| Inherited By: | AbstractStyle, Style, StyleVariation, and Theme |
| Status: | Technology preview |
Ce type est en préversion technologique et est susceptible d'être modifié.
Propriétés
- abstractButton : ControlStyle
- applicationWindow : ControlStyle
- busyIndicator : ControlStyle
- button : ControlStyle
- checkBox : ControlStyle
- checkDelegate : ControlStyle
- comboBox : ControlStyle
- control : ControlStyle
- delayButton : ControlStyle
- dial : ControlStyle
- dialog : ControlStyle
- dialogButtonBox : ControlStyle
- flatButton : ControlStyle
- frame : ControlStyle
- groupBox : ControlStyle
- itemDelegate : ControlStyle
- label : ControlStyle
- menu : ControlStyle
- menuBar : ControlStyle
- menuBarItem : ControlStyle
- menuItem : ControlStyle
- menuSeparator : ControlStyle
- page : ControlStyle
- pageIndicator : ControlStyle
- pane : ControlStyle
- popup : ControlStyle
- progressBar : ControlStyle
- radioButton : ControlStyle
- radioDelegate : ControlStyle
- roundButton : ControlStyle
- scrollBar : ControlStyle
- scrollIndicator : ControlStyle
- scrollView : ControlStyle
- searchField : ControlStyle
- slider : ControlStyle
- spinBox : ControlStyle
- swipeDelegate : ControlStyle
- switchControl : ControlStyle
- switchDelegate : ControlStyle
- tabBar : ControlStyle
- tabButton : ControlStyle
- textArea : ControlStyle
- textField : ControlStyle
- textInput : ControlStyle
- toolBar : ControlStyle
- toolButton : ControlStyle
- toolSeparator : ControlStyle
Méthodes
- ControlStyle getControlStyle(controlType)
Description détaillée
StylableControls est un type de base abstrait. Il contient un ControlStyle pour chaque type de contrôle pouvant être stylisé par un Style, Theme ou StyleVariation.
Les types de contrôles forment une hiérarchie dans laquelle les propriétés définies sur un type de base se répercutent sur les types plus spécifiques. Par exemple, attribuer un rayon de quatre à abstractButton.background.radius fera en sorte que tous les types de boutons, tels que button, checkBox et radioButton, aient un rayon de quatre.
Les extraits de code présentés sur cette page illustrent quelques-unes des propriétés clés pouvant être utilisées pour styliser chaque type de contrôle, mais ils ne sont en aucun cas exhaustifs. De nombreuses autres propriétés sont disponibles, comme indiqué dans la documentation relative à ControlStyle et DelegateStyle. Dans la pratique, certaines d'entre elles peuvent également être omises, car l'fallback style fournit déjà des valeurs par défaut raisonnables. Cela signifie que si vous supprimez simplement une propriété d'un des extraits de code, cela n'aura peut-être aucun effet sur son apparence, car celle-ci sera alors déterminée par le style de secours.
Remarque : la compatibilité des types dans les modules Qt.labs n’est pas garantie dans les versions futures.
Voir également Résolution des propriétés StyleKit.
Documentation des propriétés
abstractButton : ControlStyle
Propriété groupée permettant de styliser tous les contrôles de type bouton, notamment Button, CheckBox, RadioButton, Switch et RoundButton. Si ces propriétés ne sont pas définies, la valeur par défaut est control.
abstractButton.background.radius: 4 // all buttons get a radius of 4
checkBox.indicator.radius: 2 // except check boxes, which get a radius of 2Voir également Types de contrôles.
applicationWindow : ControlStyle
Propriété groupée pour la mise en forme ApplicationWindow.
Les propriétés non définies reprennent la valeur par défaut control.
Utilisez ` applicationWindow ` pour définir la couleur d'arrière-plan de la fenêtre :
light: Theme {
applicationWindow.background.color: "#f0f0f0"
}
dark: Theme {
applicationWindow.background.color: "#404040"
}Remarque : pour que cela prenne effet,l'application doit utiliser ` ApplicationWindow`, et non `Window`.
busyIndicator : ControlStyle
Propriété groupée pour la mise en forme : BusyIndicator.
Les propriétés non définies reprennent la valeur par défaut control.
busyIndicator {
background {
visible: false
width: 48
height: 48
}
indicator {
fillWidth: true
fillHeight: true
color: "transparent"
border.width: 0
foreground {
radius: 255
color: palette.accent
}
}
}StyleKit ne fournit pas de propriétés dédiées pour styliser l'animation de l'indicateur de chargement. Pour modifier la forme ou l'animation de l'indicateur de chargement, vous devez plutôt implémenter un indicateur personnalisé via la propriété « foreground » delegate:
busyIndicator {
background {
visible: false
width: 48
height: 48
}
indicator {
fillWidth: true
fillHeight: true
color: "transparent"
border.width: 0
foreground {
radius: 255
color: palette.accent
delegate: Text {
required property DelegateStyle delegateStyle
required property QtObject control
opacity: control.running ? 1 : 0
Behavior on opacity { NumberAnimation{} }
text: "↻"
color: delegateStyle.color
font.pixelSize: 20
RotationAnimation on rotation {
from: 0
to: 360
duration: 1000
loops: Animation.Infinite
running: control.running
}
}
}
}
}button : ControlStyle
Propriété groupée pour la mise en forme Button.
Les propriétés non définies reviennent par défaut à abstractButton.
button {
background {
width: 120
height: 40
shadow {
opacity: 0.6
color: "gray"
verticalOffset: 2
horizontalOffset: 2
}
color: "cornflowerblue"
gradient: Gradient {
// The gradient is drawn on top of the 'background.color', so
// we use semi-transparent stops to give the button some shading
// while letting the base color show through. This makes it easier
// to change the color, but keep the shading, in the hovered state below.
GradientStop { position: 0.0; color: Qt.alpha("black", 0.0)}
GradientStop { position: 1.0; color: Qt.alpha("black", 0.2)}
}
}
text.color: "white"
hovered.background.color: "royalblue"
pressed.background.scale: 0.95
}checkBox : ControlStyle
Propriété groupée pour la mise en forme CheckBox.
Les propriétés non définies reviennent par défaut à abstractButton.
checkBox {
// Hide the button background; show only the indicator and text
background.visible: false
indicator {
color: "white"
border.color: "darkslategray"
foreground {
color: "transparent"
image.source: "qrc:/qt-project.org/imports/QtQuick/Controls/Basic/images/check.png"
image.color: palette.accent
// Hide the checkmark when the checkbox is not checked
visible: false
}
}
// Show the checkmark when the checkbox is checked
checked.indicator.foreground.visible: true
}checkDelegate : ControlStyle
Propriété groupée pour la mise en forme : CheckDelegate.
Les propriétés non définies reviennent par défaut à itemDelegate.
checkDelegate {
text.alignment: Qt.AlignHCenter | Qt.AlignVCenter
background {
radius: 0
color: "white"
border.width: 0
}
indicator {
border.color: "darkslategray"
foreground {
color: "transparent"
image.source: "qrc:/qt-project.org/imports/QtQuick/Controls/Basic/images/check.png"
image.color: palette.accent
// Hide the checkmark when the checkbox is not checked
visible: false
}
}
hovered.background.color: "#f0f0f0"
// Show the checkmark when the checkbox is checked
checked.indicator.foreground.visible: true
}comboBox : ControlStyle
Propriété groupée pour la mise en forme : ComboBox.
Les propriétés non définies reprennent la valeur par défaut de control.
Remarque : appliquez le style à la fenêtre contextuelle via popup, età ses éléments via itemDelegate.
comboBox {
text.alignment: Qt.AlignHCenter | Qt.AlignVCenter
background.topLeftRadius: 4
background.topRightRadius: 4
indicator {
// Show only the dropdown arrow, not the indicator background
color: "transparent"
border.width: 0
foreground {
image.source: "qrc:/qt-project.org/imports/QtQuick/Controls/Basic/images/drop-indicator.png"
image.color: "black"
}
}
}control : ControlStyle
Propriété groupée permettant de définir le style de tous les contrôles.
control Il s'agit du type de base dans la hiérarchie des contrôles, et les propriétés définies ici servent de valeurs par défaut pour tous les autres types de contrôles. Par exemple, définir control.width: 200 donne à tous les contrôles une largeur de 200 pixels, y compris les boutons, les indicateurs de défilement et tous les autres contrôles. Cela remplace également toutes les valeurs héritées d’un niveau supérieur dans la hiérarchie de style (l’ Style pour un Theme, ou l’ fallbackStyle pour un Style), y compris les effets au survol et autres comportements liés à l’état. Utilisez control avec parcimonie, et privilégiez des types de base plus spécifiques tels que abstractButton ou pane lorsque cela est possible.
control {
padding: 8
background.radius: 4
}delayButton : ControlStyle
Propriété groupée pour la mise en forme de DelayButton.
Pour un bouton de délai, la progression est représentée à l’aide de l’indicateur. Par défaut, l’indicateur est transparent et sans bordure ; seul son premier plan est donc visible à mesure qu’il se remplit.
Les propriétés non définies reprennent les valeurs par défaut de abstractButton.
delayButton {
padding: 0
indicator {
fillWidth: true
fillHeight: true
color: "transparent"
border.width: 0
foreground.color: palette.accent
}
checked.indicator.foreground.color: palette.accent.darker(1.2)
}dial : ControlStyle
Propriété groupée pour la mise en forme : Dial.
Les propriétés non définies reviennent par défaut à control.
dial {
spacing: 0
handle.width: 15
handle.height: 15
background.visible: false
indicator {
width: 60
height: 60
radius: 255
foreground {
fillWidth: true
fillHeight: true
width: 6
height: 6
color: palette.accent
}
}
}dialog : ControlStyle
Propriété groupée pour la mise en forme : Dialog.
Les propriétés non définies reviennent par défaut à popup.
dialog {
text {
padding: 12
alignment: Qt.AlignHCenter | Qt.AlignVCenter
}
background.color: "white"
}dialogButtonBox : ControlStyle
Propriété groupée pour la mise en forme : DialogButtonBox.
Les propriétés non définies reviennent par défaut à la valeur « pane ».
dialogButtonBox {
background {
height: 40
radius: 0
color: "transparent"
border.width: 0
}
}flatButton : ControlStyle
Propriété groupée permettant de styliser les boutons plats (boutons sans arrière-plan visible à l'état normal). La mise en forme s'appliquera à une « Button » si la propriété « Button.flat » est définie sur « true ».
Les propriétés non définies reprennent la valeur par défaut de « abstractButton ».
flatButton {
// Hide background normally, show on hover
background.visible: false
hovered.background.visible: true
}frame : ControlStyle
Propriétés regroupées pour la mise en forme Frame.
Les propriétés non définies reviennent par défaut à pane.
frame {
background {
color: "#fafafa"
border.color: "#d0d0d0"
radius: 4
}
}groupBox : ControlStyle
Propriété groupée pour la mise en forme : GroupBox.
Les propriétés non définies reviennent par défaut à frame.
groupBox {
// A group box is a container for other controls, so we give it some
// padding to avoid the child controls to be too close to the border
padding: 20
// Move the label to the right, to match the radius of the background
text.leftPadding: 6
text.color: "darkslategray"
background {
// Move the frame down, below the text label
topMargin: 30
radius: 6
color: "#f8f8f8"
border.color: "#d0d0d0"
}
}itemDelegate : ControlStyle
Propriété groupée pour la mise en forme : ItemDelegate.
Les propriétés non définies reprennent la valeur par défaut de control.
Remarque : dans Qt Quick Controls, ItemDelegate hérite de AbstractButton. Dans StyleKit, cependant, itemDelegate revient par défaut à control plutôt qu’à abstractButton, car le style des délégués est généralement très différent de celui des boutons (design plat, absence de bordures ou d’ombres portées, etc.).
itemDelegate {
text.alignment: Qt.AlignVCenter | Qt.AlignLeft
background {
radius: 0
color: "white"
border.width: 0
}
hovered.background.color: "#f0f0f0"
}label : ControlStyle
Propriété groupée pour la mise en forme Label.
Les propriétés non définies reprennent la valeur par défaut control.
light: Theme {
// Labels typically have no background, so set background.visible to false.
// Alternatively, hiding the background for labels can be done once for all
// themes by setting Style.label.background.visible: false.
label.background.visible: false
label.text.color: "black"
}
dark: Theme {
label.background.visible: false
label.text.color: "white"
}menu : ControlStyle
Propriété groupée pour la mise en forme : Menu.
Les propriétés non définies reviennent par défaut à popup.
menu {
background {
width: 200
height: 40
border.color: "darkslategray"
radius: 4
}
}menuBar : ControlStyle
Propriété groupée pour la mise en forme : MenuBar.
Les propriétés non définies reprennent la valeur par défaut control.
Remarque : la mise en forme de ` MenuBar`, ` MenuBarItem` et ` MenuSeparator ` n’affecte normalement que les barres de menus non natives. Lorsqu’un ` MenuBar ` est implémenté en tant que barre de menus native, ses délégués ne sont pas utilisés pour le rendu ; par conséquent, les propriétés de style StyleKit peuvent ne produire aucun effet visuel. Voir Barres de menus natives pour plus de détails.
menuBar {
background {
radius: 0
border.width: 0
}
}menuBarItem : ControlStyle
Propriété groupée permettant de styliser les éléments de menu dans un MenuBar.
Les propriétés non définies reprennent les valeurs par défaut de control.
Remarque : dans Qt Quick Controls, un « MenuBarItem » hérite de AbstractButton. Dans StyleKit, cependant, menuBarItem est un type de contrôle distinct qui utilise par défaut control au lieu de abstractButton, car les éléments de la barre de menu ont généralement un style très différent de celui des boutons classiques (design plat, sans bordures ni ombres portées, etc.).
menuBarItem {
text.alignment: Qt.AlignLeft | Qt.AlignVCenter
background {
radius: 0
color: "transparent"
border.width: 0
}
hovered.background.color: "#c0c0c0"
}menuItem : ControlStyle
Propriété groupée pour la mise en forme : MenuItem.
Les propriétés non définies reprennent la valeur par défaut de control.
Remarque : dans Qt Quick Controls, un élément « MenuItem » hérite de AbstractButton. Dans StyleKit, cependant, menuItem revient par défaut à control au lieu de abstractButton, car le style des éléments de menu est généralement très différent de celui des boutons classiques (design plat, absence de bordures ou d’ombres portées, etc.).
menuItem {
text.alignment: Qt.AlignVCenter | Qt.AlignLeft
background {
width: 200
border.width: 0
}
indicator {
color: "transparent"
border.width: 0
foreground {
image.color: palette.accent
alignment: Qt.AlignCenter
}
first {
alignment: Qt.AlignLeft
foreground.image.source: "qrc:/qt-project.org/imports/QtQuick/Controls/Basic/images/check.png"
}
second {
alignment: Qt.AlignRight
foreground.image.source: "qrc:/qt-project.org/imports/QtQuick/Controls/Basic/images/arrow-indicator.png"
}
}
hovered.background.color: "#c0c0c0"
}menuSeparator : ControlStyle
Propriété groupée pour la mise en forme : MenuSeparator.
Les propriétés non définies reviennent par défaut à control.
menuSeparator {
background.visible: false
indicator {
width: 188
height: 1
border.width: 0
color: "#c0c0c0"
foreground.visible: false
}
}page : ControlStyle
Propriété groupée pour la mise en forme : Page.
Les propriétés non définies reprennent la valeur par défaut pane.
Notez que les propriétés ` header ` et ` footer ` d’un ` Page ` sont généralement définies par l’application sur ` ToolBar ` ou ` TabBar`, et que ces contrôles sont stylisés séparément. Pour appliquer un style alternatif à un ` ToolBar ` lorsqu’il est utilisé à l’intérieur d’un ` Page`, utilisez un ` StyleVariation` :
page {
background {
color: "white"
border.width: 0
}
variations: StyleVariation {
toolBar.background.color: "cornflowerblue"
toolButton.background.color: "skyblue"
toolButton.background.border.color: "aliceblue"
}
}pageIndicator : ControlStyle
Propriété groupée pour la mise en forme PageIndicator.
Les propriétés non définies reviennent par défaut à control.
pageIndicator {
background.visible: false
indicator {
width: 5
height: 5
radius: 255
border.width: 0
color: "black"
opacity: 0.45
foreground.visible: false
}
hovered.indicator {
width: 6
height: 6
opacity: 0.7
}
pressed.indicator {
width: 4
height: 4
}
checked.indicator {
width: 7
height: 7
}
checked.hovered.indicator {
width: 8
height: 8
opacity: 0.7
}
}pane : ControlStyle
Propriété groupée pour la mise en forme : Pane.
Les propriétés non définies reviennent par défaut à control.
pane {
background {
width: 200
height: 200
color: "white"
}
}popup : ControlStyle
Propriété groupée pour la mise en forme : Popup.
Les propriétés non définies reviennent par défaut à control.
popup {
background {
color: "white"
border.width: 1
border.color: "darkslategray"
radius: 4
}
}progressBar : ControlStyle
Propriété groupée pour la mise en forme ProgressBar. Pour une barre de progression, la rainure est mise en forme via l'indicateur, tandis que la piste de progression est mise en forme via le premier plan de l'indicateur.
Les propriétés non définies reprennent la valeur par défaut control.
progressBar {
// Hide the background; show only the progress bar
background.visible: false
indicator {
width: 150
height: 8
radius: 4
color: "#e0e0e0"
foreground {
// Set margins to add some space between the progress track and the groove
margins: 2
color: palette.accent
radius: 4
}
}
}StyleKit ne fournit pas de propriété dédiée pour styliser l’animation indéterminée d’une barre de progression. Pour modifier l’animation, vous devez plutôt implémenter un premier plan d’indicateur personnalisé delegate:
progressBar {
indicator {
width: 150
height: 8
foreground {
delegate: StyledItem {
// Draw a pulsating progress track when in indeterminate mode, and a normal track otherwise
width: control.indeterminate ? parent.width : parent.width * control.visualPosition
height: parent.height
opacity: control.indeterminate ? 0.1 : 1.0
SequentialAnimation on opacity {
running: control.indeterminate
loops: Animation.Infinite
NumberAnimation { from: 0.1; to: 1.0; duration: 500; easing.type: Easing.InOutQuad }
NumberAnimation { from: 1.0; to: 0.1; duration: 500; easing.type: Easing.InOutQuad }
}
}
}
}
}radioButton : ControlStyle
Propriété groupée pour la mise en forme RadioButton.
Les propriétés non définies reviennent par défaut à abstractButton.
radioButton {
// Hide the button background; show only the indicator and text
background.visible: false
indicator {
// Make the indicator circular
radius: 255
foreground {
// The foreground circle is what shows the checked state, so we make
// it a bit smaller than the outer circle by setting margins
margins: 4
radius: 255
// Hide the foreground circle when the radio button is not checked
visible: false
}
}
// Show the foreground circle when the radio button is checked
checked.indicator.foreground.visible: true
}radioDelegate : ControlStyle
Propriétés regroupées pour la mise en forme : RadioDelegate.
Les propriétés non définies reviennent par défaut à itemDelegate.
radioDelegate {
text.alignment: Qt.AlignVCenter | Qt.AlignLeft
background {
radius: 0
color: "white"
border.width: 0
}
indicator {
radius: 255
foreground {
margins: 4
visible: false
radius: 255
color: palette.accent
}
}
hovered.background.color: "#f0f0f0"
checked.indicator.foreground.visible: true
}roundButton : ControlStyle
Propriété groupée pour la mise en forme : RoundButton.
Les propriétés non définies reviennent par défaut à abstractButton.
roundButton {
background.radius: 255
text.alignment: Qt.AlignVCenter | Qt.AlignHCenter
}scrollBar : ControlStyle
Propriété groupée pour la mise en forme : ScrollBar. La rainure est mise en forme via background, et la poignée via indicator.
Les propriétés non définies reprennent la valeur par défaut control.
scrollBar {
padding: 0
background {
// Set the groove size and color
width: 10
height: 10
color: "white"
}
indicator {
radius: 255
fillWidth: true
width: 10
height: 10
color: "#c0c0c0"
// The indicator is so simple that it doesn't need a foreground
foreground.visible: false
}
vertical {
indicator {
// In vertical mode, the indicator should stretch vertically
// to fill the available height rather than the available width.
fillWidth: false
fillHeight: true
}
}
}scrollIndicator : ControlStyle
Propriété groupée pour la mise en forme : ScrollIndicator. La rainure est mise en forme via background, et la poignée via indicator.
Les propriétés non définies reprennent la valeur par défaut control.
scrollIndicator {
// A scroll indicator typically has no groove, just a sliding
// indicator. So hide the background, since it represents the groove.
background.visible: false
indicator {
fillWidth: true
width: 5
height: 5
border.width: 0
color: "cornflowerblue"
// The indicator is so simple that it doesn't need a foreground
foreground.visible: false
}
vertical {
indicator {
// In vertical mode, the indicator should stretch vertically
// to fill the available height rather than the available width.
fillWidth: false
fillHeight: true
}
}
}scrollView : ControlStyle
Propriété groupée pour la mise en forme de ScrollView.
ScrollView N'a en soi aucun délégué visuel à styliser. Ses barres de défilement peuvent être stylisées séparément via la propriété scrollBar. Mais vous pouvez utiliser padding pour contrôler l'espace entre les barres de défilement et la zone de contenu.
Les propriétés non définies reprennent par défaut la valeur de control.
scrollView {
// Add some space between the scroll bars and the content area
padding: 2
// For the sake of the example, style the scroll bars in a ScrollView
// differently from the default scroll bars by using a StyleVariation.
variations: StyleVariation {
scrollBar.indicator.color: "cornflowerblue"
}
}searchField : ControlStyle
Propriété groupée pour la mise en forme : SearchField.
Les propriétés non définies reprennent la valeur par défaut control.
searchField {
// Center the text between the buttons
text.padding: 5
text.alignment: Qt.AlignVCenter | Qt.AlignLeft
text.color: "black"
background.width: 200
indicator {
color: "transparent"
border.width: 0
foreground{
alignment: Qt.AlignCenter
}
// Place the search and clear buttons on the left and right side of the control
// search button
first {
alignment: Qt.AlignLeft
image.color: "black"
image.source: "qrc:/qt-project.org/imports/QtQuick/Controls/Basic/images/search-magnifier.png"
}
// clear button
second {
alignment: Qt.AlignRight
image.color: "black"
image.source: "qrc:/qt-project.org/imports/QtQuick/Controls/Basic/images/close_circle.png"
}
}
}slider : ControlStyle
Propriété groupée pour la mise en forme de Slider. Pour un curseur, la rainure est mise en forme via l’indicateur, tandis que la barre de progression est mise en forme via le premier plan de l’indicateur.
Les propriétés non définies reprennent la valeur par défaut control.
Pour les curseurs verticaux, inversez les propriétés ` width ` et ` height ` des délégués concernés afin que le contrôle soit plus haut que large, comme indiqué dans l'extrait de code ci-dessous.
slider {
background {
// The background is hidden, but its implicit size still
// determines the overall implicit size of the control.
visible: false
width: 150
height: 50
}
indicator {
// The groove of the slider should fill out the entire width of the control
fillWidth: true
height: 8
radius: 255
color: "#e0e0e0"
foreground {
radius: 255
color: palette.accent
}
}
handle {
width: 24
height: 24
radius: 255
color: "white"
border.color: "#c0c0c0"
}
vertical {
// Transpose relevant geometry
background {
width: 50
height: 150
}
indicator {
fillWidth: false
fillHeight: true
width: 8
}
}
}spinBox : ControlStyle
Propriété groupée pour la mise en forme : SpinBox.
Les propriétés non définies reprennent la valeur par défaut control.
spinBox {
// Center the text between the up/down buttons
text.alignment: Qt.AlignHCenter | Qt.AlignVCenter
indicator {
color: "transparent"
border.width: 0
foreground {
image.source: "qrc:/qt-project.org/imports/QtQuick/Controls/Basic/images/arrow-indicator.png"
image.color: "black"
alignment: Qt.AlignCenter
}
// Place the down and up buttons on the left and right side of the control
// up button
first {
alignment: Qt.AlignRight
foreground.rotation: -90
}
// down button
second {
alignment: Qt.AlignLeft
foreground.rotation: 90
}
}
}Remarque : pour l'instant,il est uniquement possible de positionner les boutons haut et bas à gauche ou à droite du contrôle, mais pas l'un au-dessus de l'autre.
swipeDelegate : ControlStyle
Propriété groupée pour la mise en forme : SwipeDelegate.
Les propriétés non définies reprennent la valeur par défaut « itemDelegate ».
swipeDelegate {
text.alignment: Qt.AlignVCenter | Qt.AlignLeft
background {
radius: 0
color: "white"
border.width: 0
}
hovered.background.color: "#f0f0f0"
}switchControl : ControlStyle
Propriété groupée pour la mise en forme : Switch.
Les propriétés non définies reviennent par défaut à abstractButton.
switchControl {
// For a switch control, we typically don't want a background, only an indicator with a handle
background.visible: false
indicator {
radius: 12
foreground {
// Add some space between the indicator and the foreground track
margins: 2
radius: 12
// The foreground track should only be visible when the switch is checked
visible: false
}
}
checked.indicator.foreground.visible: true
handle {
// Add some space between the handle and the indicator
leftMargin: 2
rightMargin: 2
width: 20
height: 20
radius: 255
color: "white"
}
}switchDelegate : ControlStyle
Propriété groupée pour la mise en forme : SwitchDelegate.
Les propriétés non définies reviennent par défaut à itemDelegate.
switchDelegate {
text.alignment: Qt.AlignVCenter | Qt.AlignLeft
background {
radius: 0
color: "white"
border.width: 0
}
indicator {
radius: 12
foreground {
// Add some space between the indicator and the foreground track
margins: 2
radius: 12
// The foreground track should only be visible when the switch is checked
visible: false
}
}
handle {
// Add some space between the handle and the indicator
leftMargin: 2
rightMargin: 2
width: 20
height: 20
radius: 255
color: "white"
}
hovered.background.color: "#f0f0f0"
checked.indicator.foreground.visible: true
}tabBar : ControlStyle
Propriété groupée pour la mise en forme : TabBar.
Les propriétés non définies reprennent la valeur par défaut pane.
tabBar {
padding: 0
spacing: -1 // let tab buttons overlap slightly
background {
color: "white"
border.width: 0
}
}tabButton : ControlStyle
Propriété groupée pour la mise en forme : TabButton.
Les propriétés non définies reviennent par défaut à abstractButton.
tabButton {
background {
radius: 0
topLeftRadius: 4
topRightRadius: 4
color: "#e8e8e8"
}
checked.background.color: "white"
}textArea : ControlStyle
Propriété groupée pour la mise en forme : TextArea.
Les propriétés non définies reviennent par défaut à textInput.
textArea {
// Add some space between the text and the border of the text area
padding: 8
text.color: "black"
background {
color: "white"
border.color: "#c0c0c0"
}
focused.background.border.color: palette.accent
}textField : ControlStyle
Propriété groupée pour la mise en forme : TextField.
Les propriétés non définies reviennent par défaut à textInput.
textField {
// Add some space between the text and the border of the text field
padding: 8
text.alignment: Qt.AlignVCenter
background {
width: 150
color: "white"
border.color: "#c0c0c0"
}
focused.background.border.color: palette.accent
}textInput : ControlStyle
Propriété groupée permettant de styliser tous les contrôles de saisie de texte, y compris TextField et TextArea.
Les propriétés non définies reprennent la valeur par défaut « control ».
textInput {
// Add some space between the text and the border of the text input
padding: 8
text.color: "black"
background {
color: "white"
border.width: 1
border.color: "#c0c0c0"
}
}toolBar : ControlStyle
Propriété groupée pour la mise en forme : ToolBar.
Les propriétés non définies reviennent par défaut à pane.
toolBar {
spacing: 2
background {
radius: 0
height: 40
border.width: 1
}
}toolButton : ControlStyle
Propriété groupée pour la mise en forme ToolButton.
Les propriétés non définies reviennent par défaut à abstractButton.
toolButton {
background.radius: 0
}toolSeparator : ControlStyle
Propriété groupée pour la mise en forme ToolSeparator.
Les propriétés non définies reprennent la valeur par défaut « control ».
Pour les séparateurs verticaux, inversez les valeurs « width » et « height » des délégués concernés afin que le contrôle soit plus haut que large, comme indiqué dans l'extrait de code ci-dessous.
toolSeparator {
background {
// The background is hidden, but its implicit size still
// determines the overall implicit size of the control.
visible: false
width: 10
height: 10
}
indicator {
width: 30
height: 1
border.width: 0
color: "#c0c0c0"
alignment: Qt.AlignCenter
foreground.visible: false
}
vertical {
indicator {
width: 1
height: 30
}
}
}Documentation de la méthode
ControlStyle getControlStyle(controlType)
Renvoie l'ControlStyle pour l'controlType donné, ou null, si aucun ControlStyle n'a été défini pour ce type.
controlType Il peut s’agir de l’un des types intégrés documentés par StyleReader.controlType, ou de l’ controlType d’un CustomControl.
Cette fonction peut être utilisée, par exemple, pour lire ou écrire une propriété du style d’un « CustomControl » lors de l’exécution :
Style {
id: myStyle
property int customButtonType: 0
CustomControl {
controlType: myStyle.customButtonType
background.color: "green"
}
}
function changeButtonColor() {
let customControlStyle = myStyle.getControlStyle(style.customButtonType)
customControlStyle.background.color = "yellowgreen"
// You can also access the style definition in the theme, if it has one
// myStyle.theme.getControlStyle(StyleReader.Button).padding = 10
}Si controlType est un type intégré (tel que StyleReader.Button), l’utilisation, par exemple, de myStyle.button ou de myStyle.getControlStyle(StyleReader.Button) pour obtenir l’ ControlStyle est pratiquement équivalente. La différence réside dans le fait que la première créera paresseusement un ControlStyle s’il n’est pas encore défini, tandis que la seconde renverra à la place null. Cela signifie que, par exemple, myStyle.button.padding = 10 est toujours sans risque, tandis que myStyle.getControlStyle(StyleReader.Button).padding = 10 échouera si myStyle.button n’a pas été défini dans le Style.
Voir également CustomControl et StyleReader.
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.