StylableControls QML Type
Tipo base abstracto que contiene los tipos de control a los que se les puede aplicar un estilo. Más información...
| Import Statement: | import Qt.labs.StyleKit |
| Inherited By: | AbstractStyle, Style, StyleVariation, and Theme |
| Status: | Technology preview |
Este tipo se encuentra en fase de vista previa tecnológica y está sujeto a cambios.
Propiedades
- 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étodos
- ControlStyle getControlStyle(controlType)
Descripción detallada
StylableControls es un tipo base abstracto. Contiene un ` ControlStyle ` para cada tipo de control al que se le puede aplicar un estilo mediante un ` Style`, ` Theme` o ` StyleVariation`.
Los tipos de control forman una jerarquía en la que las propiedades establecidas en un tipo base se propagan hacia los tipos más específicos. Por ejemplo, asignar un radio de cuatro a « abstractButton.background.radius » hará que todos los tipos de botón, como « button », « checkBox » y « radioButton », tengan un radio de cuatro.
Los fragmentos de código de esta página ilustran algunas de las propiedades clave que se pueden utilizar para aplicar estilos a cada tipo de control, pero no son en absoluto exhaustivos. Hay muchas otras propiedades disponibles, tal y como se describe en la documentación de ControlStyle y DelegateStyle. En la práctica, algunas de ellas también pueden omitirse, ya que el fallback style ya proporciona valores por defecto adecuados. Esto significa que, si simplemente eliminas una propiedad de uno de los fragmentos de código, es posible que no afecte realmente a su apariencia, ya que, en su lugar, se aplicará el estilo por defecto.
Nota: No se garantiza que los tipos de los módulos de Qt.labs sigan siendo compatibles en futuras versiones.
Véase también Resolución de propiedades de StyleKit.
Documentación de propiedades
abstractButton : ControlStyle
Propiedad agrupada para aplicar estilos a todos los controles similares a botones, incluidos Button, CheckBox, RadioButton, Switch y RoundButton. Las propiedades no definidas se sustituyen por control.
abstractButton.background.radius: 4 // all buttons get a radius of 4
checkBox.indicator.radius: 2 // except check boxes, which get a radius of 2Véase también «Tipos decontrol».
applicationWindow : ControlStyle
Propiedad agrupada para aplicar estilos: ApplicationWindow.
Las propiedades no definidas se sustituyen por control.
Utiliza ` applicationWindow ` para establecer el color de fondo de la ventana:
light: Theme {
applicationWindow.background.color: "#f0f0f0"
}
dark: Theme {
applicationWindow.background.color: "#404040"
}Nota: Para que esto surta efecto,la aplicación debe utilizar ` ApplicationWindow`, no `Window`.
busyIndicator : ControlStyle
Propiedad agrupada para aplicar estilos: BusyIndicator.
Las propiedades no definidas se sustituyen por 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 no proporciona propiedades específicas para aplicar estilos a la animación del indicador giratorio. Para cambiar la forma o la animación del indicador giratorio, debes implementar un indicador personalizado en primer plano delegate en su lugar:
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
Propiedad agrupada para aplicar estilos: Button.
Las propiedades no definidas se sustituyen por 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
Propiedad agrupada para aplicar estilos: CheckBox.
Las propiedades no definidas se sustituyen por 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
Propiedad agrupada para aplicar estilos: CheckDelegate.
Las propiedades no definidas se sustituyen por 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
Propiedad agrupada para aplicar estilos: ComboBox.
Las propiedades no definidas se sustituyen por control.
Nota: Aplica el estilo a la ventana emergente mediante popup y a sus elementos mediante 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
Propiedad agrupada para aplicar estilos a todos los controles.
control Es el tipo base en la jerarquía de controles, y las propiedades que se establecen aquí sirven como valores por defecto para todos los demás tipos de control. Por ejemplo, al establecer « control.width: 200 », todos los controles pasan a tener 200 píxeles de ancho, incluidos los botones, los indicadores de desplazamiento y cualquier otro control. También anula cualquier valor heredado de un nivel superior en la jerarquía de estilos (el ` Style ` para un ` Theme`, o el ` fallbackStyle ` para un ` Style`), incluidos los efectos al pasar el cursor y otros comportamientos basados en el estado. Utiliza ` control ` con moderación y, siempre que sea posible, da preferencia a tipos base más específicos como ` abstractButton ` o ` pane `.
control {
padding: 8
background.radius: 4
}delayButton : ControlStyle
Propiedad agrupada para aplicar estilos a DelayButton.
En el caso de un botón de retraso, el progreso se muestra mediante el indicador. Por defecto, el indicador es transparente y no tiene borde, por lo que solo se ve la parte frontal del indicador a medida que se va llenando.
Las propiedades no definidas recurren a 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
Propiedad agrupada para aplicar estilos: Dial.
Las propiedades no definidas adoptan el valor predeterminado de 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
Propiedad agrupada para aplicar estilos: Dialog.
Las propiedades no definidas adoptan por defecto el valor de popup.
dialog {
text {
padding: 12
alignment: Qt.AlignHCenter | Qt.AlignVCenter
}
background.color: "white"
}dialogButtonBox : ControlStyle
Propiedad agrupada para aplicar estilos: DialogButtonBox.
Las propiedades no definidas se sustituyen por pane.
dialogButtonBox {
background {
height: 40
radius: 0
color: "transparent"
border.width: 0
}
}flatButton : ControlStyle
Propiedad agrupada para aplicar estilos a botones planos (botones sin fondo visible en su estado normal). El estilo se aplicará a un « Button » si « Button.flat » se establece en « true ».
Las propiedades no configuradas adoptan por defecto el valor abstractButton.
flatButton {
// Hide background normally, show on hover
background.visible: false
hovered.background.visible: true
}frame : ControlStyle
Propiedad agrupada para aplicar estilos: Frame.
Las propiedades no definidas se sustituyen por pane.
frame {
background {
color: "#fafafa"
border.color: "#d0d0d0"
radius: 4
}
}groupBox : ControlStyle
Propiedad agrupada para aplicar estilos: GroupBox.
Las propiedades no definidas se sustituyen por 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
Propiedad agrupada para aplicar estilos: ItemDelegate.
Las propiedades no definidas se sustituyen por control.
Nota: En los controles de Qt Quick, ItemDelegate hereda de AbstractButton. Sin embargo, en StyleKit, itemDelegate recurre a control en lugar de a abstractButton, ya que los delegados suelen tener un estilo muy diferente al de los botones (planos, sin bordes ni sombras, etc.).
itemDelegate {
text.alignment: Qt.AlignVCenter | Qt.AlignLeft
background {
radius: 0
color: "white"
border.width: 0
}
hovered.background.color: "#f0f0f0"
}label : ControlStyle
Propiedad agrupada para aplicar estilos: Label.
Las propiedades no definidas se sustituyen por 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
Propiedad agrupada para aplicar estilos: Menu.
Las propiedades no definidas se sustituyen por popup.
menu {
background {
width: 200
height: 40
border.color: "darkslategray"
radius: 4
}
}menuBar : ControlStyle
Propiedad agrupada para el estilo: MenuBar.
Las propiedades no definidas se sustituyen por control.
Nota: La aplicación de estilos a MenuBar, MenuBarItem y MenuSeparator normalmente solo afecta a las barras de menú no nativas. Cuando un MenuBar se implementa como una barra de menú nativa, sus delegados no se utilizan para la representación, por lo que es posible que las propiedades de estilo de StyleKit no tengan ningún efecto visual. Consulta «Barras de menú nativas» para obtener más detalles.
menuBar {
background {
radius: 0
border.width: 0
}
}menuBarItem : ControlStyle
Propiedad agrupada para aplicar estilos a los elementos del menú en un MenuBar.
Las propiedades no definidas se sustituyen por el valor predeterminado de control.
Nota: En los controles de Qt Quick, un « MenuBarItem » hereda de « AbstractButton ». Sin embargo, en StyleKit, « menuBarItem » es un tipo de control independiente que recurre a « control » en lugar de a « abstractButton », ya que los elementos de la barra de menú suelen tener un estilo muy diferente al de los botones normales (planos, sin bordes ni sombras, etc.).
menuBarItem {
text.alignment: Qt.AlignLeft | Qt.AlignVCenter
background {
radius: 0
color: "transparent"
border.width: 0
}
hovered.background.color: "#c0c0c0"
}menuItem : ControlStyle
Propiedad agrupada para aplicar estilos: MenuItem.
Las propiedades no definidas se sustituyen por control.
Nota: En los controles de Qt Quick, un « MenuItem » hereda de AbstractButton. Sin embargo, en StyleKit, menuItem recurre a control en lugar de a abstractButton, ya que los elementos de menú suelen tener un estilo muy diferente al de los botones normales (planos, sin bordes ni sombras, 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
Propiedad agrupada para aplicar estilos: MenuSeparator.
Las propiedades no definidas se sustituyen por control.
menuSeparator {
background.visible: false
indicator {
width: 188
height: 1
border.width: 0
color: "#c0c0c0"
foreground.visible: false
}
}page : ControlStyle
Propiedad agrupada para aplicar estilos Page.
Las propiedades no definidas recurren a pane.
Ten en cuenta que las propiedades « header » y « footer » de un « Page » suelen ser establecidas por la aplicación como « ToolBar » o « TabBar », y que el estilo de esos controles se aplica por separado. Para aplicar un estilo alternativo a un « ToolBar » cuando se utiliza dentro de un « Page », utiliza 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
Propiedad agrupada para aplicar estilos: PageIndicator.
Las propiedades no definidas se sustituyen por 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
Propiedad agrupada para aplicar estilos: Pane.
Las propiedades no definidas se sustituyen por control.
pane {
background {
width: 200
height: 200
color: "white"
}
}popup : ControlStyle
Propiedad agrupada para el estilo Popup.
Las propiedades no definidas se sustituyen por control.
popup {
background {
color: "white"
border.width: 1
border.color: "darkslategray"
radius: 4
}
}progressBar : ControlStyle
Propiedad agrupada para aplicar estilos a ProgressBar. En el caso de una barra de progreso, el estilo de la ranura se aplica a través del indicador, mientras que el de la línea de progreso se aplica a través del primer plano del indicador.
Las propiedades no definidas recurren al valor predeterminado 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 no ofrece una propiedad específica para aplicar estilos a la animación indeterminada de una barra de progreso. Para modificar la animación, es necesario implementar un primer plano del indicador personalizado delegate en su lugar:
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
Propiedad agrupada para aplicar estilos a « RadioButton ».
Las propiedades no definidas se sustituyen por 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
Propiedad agrupada para aplicar estilos: RadioDelegate.
Las propiedades no definidas se sustituyen por 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
Propiedad agrupada para aplicar estilos: RoundButton.
Las propiedades no definidas se sustituyen por abstractButton.
roundButton {
background.radius: 255
text.alignment: Qt.AlignVCenter | Qt.AlignHCenter
}scrollBar : ControlStyle
Propiedad agrupada para aplicar estilos: ScrollBar. El surco se personaliza mediante background, y el tirador mediante indicator.
Las propiedades no definidas se restablecen a 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
Propiedad agrupada para aplicar estilos: ScrollIndicator. El surco se personaliza mediante background, y el tirador mediante indicator.
Las propiedades no definidas se sustituyen por 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
Propiedad agrupada para aplicar estilos a ScrollView.
ScrollView En sí misma no tiene elementos visuales a los que aplicar estilos. Sus barras de desplazamiento se pueden personalizar por separado mediante la propiedad ` scrollBar `. Sin embargo, puedes utilizar ` padding ` para controlar el espacio entre las barras de desplazamiento y el área de contenido.
Las propiedades no definidas adoptan el valor predeterminado 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
Propiedad agrupada para aplicar estilos a « SearchField ».
Las propiedades no definidas se sustituyen por 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
Propiedad agrupada para aplicar estilos a « Slider ». En el caso de un control deslizante, el estilo de la ranura se aplica a través del indicador, mientras que el de la barra de progreso se aplica a través del primer plano del indicador.
Las propiedades no definidas se sustituyen por control.
En el caso de los controles deslizantes verticales, intercambia los valores de « width » y « height » de los delegados correspondientes, de modo que el control sea más alto que ancho, tal y como se muestra en el fragmento de código siguiente.
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
Propiedad agrupada para aplicar estilos: SpinBox.
Las propiedades no definidas se sustituyen por 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
}
}
}Nota: Actualmente soloes posible colocar los botones de subir y bajar a la izquierda o a la derecha del control, pero no uno encima del otro.
swipeDelegate : ControlStyle
Propiedad agrupada para aplicar estilos: SwipeDelegate.
Las propiedades no definidas se sustituyen por itemDelegate.
swipeDelegate {
text.alignment: Qt.AlignVCenter | Qt.AlignLeft
background {
radius: 0
color: "white"
border.width: 0
}
hovered.background.color: "#f0f0f0"
}switchControl : ControlStyle
Propiedad agrupada para aplicar estilos: Switch.
Las propiedades no definidas se sustituyen por 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
Propiedad agrupada para aplicar estilos: SwitchDelegate.
Las propiedades no definidas se sustituyen por 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
Propiedad agrupada para aplicar estilos: TabBar.
Las propiedades no definidas se sustituyen por pane.
tabBar {
padding: 0
spacing: -1 // let tab buttons overlap slightly
background {
color: "white"
border.width: 0
}
}tabButton : ControlStyle
Propiedad agrupada para aplicar estilos: TabButton.
Las propiedades no definidas se sustituyen por abstractButton.
tabButton {
background {
radius: 0
topLeftRadius: 4
topRightRadius: 4
color: "#e8e8e8"
}
checked.background.color: "white"
}textArea : ControlStyle
Propiedad agrupada para aplicar estilos: TextArea.
Las propiedades no definidas se sustituyen por 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
Propiedad agrupada para aplicar estilos TextField.
Las propiedades no definidas se sustituyen por 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
Propiedad agrupada para aplicar estilos a todos los controles de entrada de texto, incluidos TextField y TextArea.
Las propiedades no definidas se sustituyen por ` 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
Propiedad agrupada para aplicar estilos: ToolBar.
Las propiedades no definidas se sustituyen por pane.
toolBar {
spacing: 2
background {
radius: 0
height: 40
border.width: 1
}
}toolButton : ControlStyle
Propiedad agrupada para aplicar estilos: ToolButton.
Las propiedades no definidas se sustituyen por abstractButton.
toolButton {
background.radius: 0
}toolSeparator : ControlStyle
Propiedad agrupada para aplicar estilos: ToolSeparator.
Las propiedades no definidas adoptan por defecto el valor de control.
Para los separadores verticales, intercambia los valores « width » y « height » de los delegados correspondientes, de modo que el control sea más alto que ancho, tal y como se muestra en el fragmento de código siguiente.
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
}
}
}Documentación del método
ControlStyle getControlStyle(controlType)
Devuelve el ` ControlStyle ` correspondiente al ` controlType` dado, o ` null`, si no se ha definido ningún ` ControlStyle ` para ese tipo.
controlType Puede ser uno de los tipos integrados documentados en StyleReader.controlType, o el controlType de un CustomControl.
Esta función se puede utilizar, por ejemplo, para leer o escribir una propiedad del estilo de un « CustomControl » en tiempo de ejecución:
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 es un tipo integrado (como StyleReader.Button), utilizar, por ejemplo, myStyle.button o myStyle.getControlStyle(StyleReader.Button) para obtener el ControlStyle es prácticamente equivalente. La diferencia radica en que el primero creará de forma diferida un ControlStyle si aún no está definido, mientras que el segundo devolverá null. Esto significa que, por ejemplo, myStyle.button.padding = 10 siempre es seguro, mientras que myStyle.getControlStyle(StyleReader.Button).padding = 10 fallará si myStyle.button no se ha definido en el Style.
Véase también CustomControl y 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.