Search code examples
qtbuttonqmlqtquick2qtquickcontrols

Aliases on styles


Why cannot define aliases for Styles? For instance

Button {

    property alias color: theText.color

    style: ButtonStyle {
        label: Text {
            id: theThext  
        }
    }
}

gives an

qml invalid alias reference unable to find id for theText


Solution

  • Similarly to this answer, it's because the item that the alias refers to is loaded dynamically. Style components like Label are just that: Components. They are templates that are used to create the actual style Items which are actually loaded with Loader.