Quantcast
Viewing all articles
Browse latest Browse all 4972

Qt Quick Controls change background

button and label are defined as components and not items. In practice it means that you cannot “see” them in the same scope like you are assuming here. A simple solution is to animate this without using state:   import QtQuick 2.1 import QtQuick.Controls 1.0 import QtQuick.Controls.Styles 1.0   ApplicationWindow{     id:win       Rectangle {         Button {             id: btn1             text: "A button"             style: ButtonStyle {                 background: Rectangle {                     id: btnBackground                     implicitWidth: 100                     implicitHeight: 25                     border.width: control.activeFocus ? 2 : 1                     border.color: control.hovered? "red" : "white"                     color: control.hovered? "white" : "red"                     Behavior on border.color {                         ColorAnimation{                             duration: 400                             easing.type: Easing.InOutQuad                         }                     }                     Behavior on color {                         ColorAnimation {                             duration: 400                             easing.type:Easing.InOutQuad                         }                     }                     radius: 4                 }                 label: Text {                     id: btnText                     text: btn1.text                     color: control.hovered? "red" : "white"                     Behavior on color {                         ColorAnimation{                             duration: 400                             easing.type: Easing.InOutQuad                         }                     }                     horizontalAlignment: Text.AlignHCenter                 }             }         }     } }

Viewing all articles
Browse latest Browse all 4972

Trending Articles