Important: Please read the Qt Code of Conduct -

How to change label text style dynamically

  • So I would like to change the text style of a label once you click on it.

    There is a title, click on it and it should open the drawer and change title text color and change anchors from right to left.

    Any help or a link would be really great.

    Thanks !

    This is what I have now:

    Item { 
        id: item
        width: parent.width
        height: parent.height   
        Label {
             id: title
             text: qsTrId("Title")
             font.pixelSize: Theme.fontSizeLarge
             height: Theme.fontSizeLarge
             color: Theme.secondaryHighlightColor
             property alias titletext: title.text
             anchors {
                    right: item.right
                    leftMargin: Theme.paddingLarge
                    rightMargin: Theme.paddingLarge
                    topMargin: Theme.paddingLarge
                    bottomMargin: Theme.paddingLarge
             MouseArea {
                      anchors.fill: title
                      onClicked: { = !
                          if (clicked) {
                      function openDrawerFunction() {
                          if (! title.titletext = "Title" ;
                          if ( title.titletext = "Title   100°C – 200°C"

    I also not sure if that is the way to do it but opening/closing the drawer and changing title text works.

Log in to reply