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
                    top: item.top
                    leftMargin: Theme.paddingLarge
                    rightMargin: Theme.paddingLarge
                    topMargin: Theme.paddingLarge
                    bottomMargin: Theme.paddingLarge
             }
             
             MouseArea {
                      anchors.fill: title
                      onClicked: { drawer.open = !drawer.open
                          if (clicked) {
                              openDrawerFunction();
                          }
                      }
                      function openDrawerFunction() {
                          if (!drawer.open) title.titletext = "Title" ;
                          if (drawer.open) 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
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.