Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Set dynamic text via function
Forum Updated to NodeBB v4.3 + New Features

Set dynamic text via function

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
8 Posts 4 Posters 607 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Meistermosher
    wrote on last edited by
    #1

    Ok that's kinda weird (but perhaps it's another Qt6 Bug?)

    Currently I try to change the text of this Text Element. And I'm really stuck :/

    It's

    Text{
        id: welcomeText
        anchors.top: chargingBackground.bottom
        anchors.horizontalCenter: chargingBackground.horizontalCenter
        anchors.topMargin: 20
        text: qsTr("Please select your charging pod!")
        property alias infoText: welcomeText.text
        font.pointSize: 20
        font.family: "Helvetica"
    }
    
    function slotSelected(id)
    {
        if(!hpcManager.chargerIsOccupied())
        {
            hpcManager.setCurrentCharger(id)
            t.running = false
        }
        else
        {
            console.log("No more parking spaces available!");
            welcomeText.infoText = "No more parking spaces available!";
        }
    }
    

    all in "root" space.
    It all works fine. The Console logs properly... but the text doesn't change. What am I missing here?
    I tried to apply the alias at different levels (because I found it written that way in other solutions) but I can't make it work.

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Code looks correct. Perhaps it is a bug, like you say. Can you test with Qt 5.15?

      (Z(:^

      M 1 Reply Last reply
      0
      • M Offline
        M Offline
        Meistermosher
        wrote on last edited by
        #3

        Jepp. Need to download it first, but I'll try.

        1 Reply Last reply
        0
        • sierdzioS sierdzio

          Code looks correct. Perhaps it is a bug, like you say. Can you test with Qt 5.15?

          M Offline
          M Offline
          Meistermosher
          wrote on last edited by
          #4

          @sierdzio Nope, doesn't work either with 5.15 :/

          J.HilkJ 1 Reply Last reply
          0
          • M Meistermosher

            @sierdzio Nope, doesn't work either with 5.15 :/

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @Meistermosher it has to be somewhere else in your code, this basic example works just fine:

            import QtQuick 2.12
            import QtQuick.Window 2.12
            import QtQuick.Controls 1.4
            
            Window {
                visible: true
                width: 640
                height: 480
            
                Button{
                    id:btn
                    anchors{
                        left: parent.left
                        right: parent.right
                        top: parent.top
                    }
                    height: 50
            
                    text: "Change text"
                    onClicked: slotSelected(1)
                }
            
                Text{
                    id: welcomeText
                    anchors.top: btn.bottom
                    anchors.horizontalCenter: btn.horizontalCenter
                    anchors.topMargin: 20
                    text: qsTr("Please select your charging pod!")
                    property alias infoText: welcomeText.text
                    font.pointSize: 20
                    font.family: "Helvetica"
                }
            
                function slotSelected(id)
                {
                    console.log("slotSelected", id)
                    console.log("No more parking spaces available!");
                    welcomeText.infoText = "No more parking spaces available!";
                }
            }
            

            2adc9264-4efd-4c33-a5cc-9c74688d26c8-image.png

            7a4fa22b-4fb8-4d43-8553-a195ad34bea2-image.png


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            1
            • M Offline
              M Offline
              Meistermosher
              wrote on last edited by
              #6

              Damn. I was sure, I figured it out the right way but encountered a bug. So please, what have I messed up here?

              import QtQuick 2.12
              import QtQuick.Controls 2.12
              //import de.martingebske
              
              
              Item {
                  id: wsRoot
                  Image{
                      id: background
                      source: "qrc:/Assets/Img/background_2.png"
                      height: 768
                      width: 1024
                      anchors.fill: parent
                  }
              
                  Rectangle{
                      id: whiteBack
                      color: "white"
                      opacity: 0.1
                      anchors.horizontalCenter: parent.horizontalCenter
                      anchors.top: parent.top
                      anchors.topMargin: 100
                      height: 300
                      width: 700
                  }
              
              
                  // Charger Selection
              
                  Rectangle {
                      id: chargingBackground
                      anchors.fill: whiteBack
                      color: "transparent"
              
                      Row{
                          id: chRow
                          anchors.fill: parent
                          spacing: 20
                          topPadding: 20
                          leftPadding: 30
              
                          ChargingSlot{
                              id: ccs1
                              source: "qrc:/Assets/Img/ccs_logo.png"
                              kw: "300kW"
                              onClicked: slotSelected(1)
                          }
                          ChargingSlot{
                              id: ccs2
                              source: "qrc:/Assets/Img/ccs_logo.png"
                              kw: "300kW"
                              onClicked: slotSelected(2)
                          }
                          ChargingSlot{
                              id: ac
                              source: "qrc:/Assets/Img/ac_logo.png"
                              itemHeight: 150
                              itemWidth: 150
                              kw: "42kW"
                              textMargin: -120
                              onClicked: slotSelected(3)
                          }
                      }
                  }
              
                  Text{
                      id: welcomeText
                      color: "white"
                      anchors.top: chargingBackground.bottom
                      anchors.horizontalCenter: chargingBackground.horizontalCenter
                      anchors.topMargin: 20
                      text: qsTr("Please select your charging pod!")
                      property alias infoText: welcomeText.text
                      font.pointSize: 20
                      font.family: "Helvetica"
                  }
              
                  function slotSelected(id)
                  {
                      if(!hpcManager.chargerIsOccupied())
                      {
                          hpcManager.setCurrentCharger(id)
                          t.running = false
                      }
                      else
                      {
                          welcomeText.infoText = "No more parking spaces available!";
                          console.log("No more parking spaces available!");
                      }
                  }
              
                  Rectangle{
                      id: footer
                      height: 50
                      width: wsRoot.width
                      anchors.bottom: wsRoot.bottom
                      color: "transparent"
              
                      Column{
                          anchors.verticalCenter: parent.verticalCenter
                          leftPadding:  30
                          Text{
                              id: date
                              color: "white"
                              font.pointSize: 10
                              text: "Datum: 23.01.1992"
                          }
                          Text {
                              id: time
                              color: "white"
                              font.pointSize: 10
                              text: "Uhrzeit: 22:22:01 Uhr"
                          }
                      }
              
                      Row{
                          anchors.right: parent.right
                          height: parent.height
                          rightPadding: 30
                          spacing: 40
              
                          Rectangle{
                              id: lanBtn
                              height: 35
                              width: 80
                              color: "transparent"
                              border.color: "white"
                              Image {
                                  anchors.verticalCenter: parent.verticalCenter
                                  source: "/Assets/Img/language_icon.png"
                                  anchors.centerIn: parent
                                  width: 30
                                  fillMode: Image.PreserveAspectFit
                              }
                              MouseArea{
                                  anchors.fill: parent
                                  onClicked: {languagePopup.open(); t.running = false}
              
                              }
                          }
                          Rectangle{
                              id: helpBtn
                              height: 35
                              width: 80
                              color: "transparent"
                              border.color: "white"
                              Text{
                                  anchors.verticalCenter: parent.verticalCenter
                                  anchors.centerIn: parent
                                  font.family: "Helvetica"
                                  text: qsTr("Help")
                                  font.pointSize: 12
                                  color: "white"
                              }
                              MouseArea{
                                  anchors.fill: parent
                                  onClicked: {console.log("Help Select!"); t.running = false}
                              }
                          }
                      }
                  }
              
                  Popup{
                      id: languagePopup
                      anchors.centerIn: parent
                      width: 600
                      height: 200
                      modal: true
                      focus: true
                      closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
              
                      ImageButton{
              
                      }
              
                      Button {
                          id: closeButton
                          anchors.bottom: parent.bottom
                          anchors.horizontalCenter: parent.horizontalCenter
                          text: "Close"
                          onClicked: languagePopup.close()
                      }
                  }
              
                  LoadManager{
                      id:l
                  }
              
                  Timer{
                      id: t
                      interval: 5000
                      running: true
                      onTriggered: lm.source = "IdleScreen.qml"
                  }
              }
              
              
              1 Reply Last reply
              0
              • GrecKoG Offline
                GrecKoG Offline
                GrecKo
                Qt Champions 2018
                wrote on last edited by
                #7

                Provide a minimal reproducible example of your problem if you want help.
                It shouldn't need any outside dependencies (here I see ChargingSlot, LoadManager, IdleScreen.qml, the different images), fit in a single file if possible and be the most minimal as possible.
                By doing this you'll most likely figure out the issue by yourself too.

                M 1 Reply Last reply
                1
                • GrecKoG GrecKo

                  Provide a minimal reproducible example of your problem if you want help.
                  It shouldn't need any outside dependencies (here I see ChargingSlot, LoadManager, IdleScreen.qml, the different images), fit in a single file if possible and be the most minimal as possible.
                  By doing this you'll most likely figure out the issue by yourself too.

                  M Offline
                  M Offline
                  Meistermosher
                  wrote on last edited by
                  #8

                  @GrecKo Ok, it was kinda connected to my Custom Image Button which ... I think overwrites the clicked function.

                  import QtQuick 2.0
                  import de.martingebske
                  
                  Rectangle{
                      id: root
                      height: 200
                      width: 200
                      color: "transparent"
                  
                      property string kw: ""
                      property string source: ""
                      property double itemHeight: 200
                      property double itemWidth: 200
                      property double textMargin: -70
                  
                      signal clicked()
                  
                      Image {
                          id: img
                          source: root.source
                          height: root.itemHeight
                          width: root.itemWidth
                  
                          Text{
                              id: txt
                              color: "white"
                              anchors.bottom: img.bottom
                              anchors.horizontalCenter: img.horizontalCenter
                              anchors.bottomMargin: root.textMargin
                              text: root.kw
                              font.pointSize: 20
                              font.family: "Helvetica"
                          }
                  
                          MouseArea{
                              id: ma
                              anchors.fill: img
                              enabled: true
                              onClicked: {
                                  if(!hpcManager.chargerIsOccupied()){
                                      root.clicked()
                                      img.opacity = 0.2;
                                      txt.opacity = 0.6;
                                      ma.enabled = false
                                  }
                                  else
                                      console.log("No more parking spaces available!")
                              }
                          }
                      }
                  }
                  

                  When I use regular Buttons instead of my custom buttons it works as intended.
                  Still I don't really get it, why the text doesn't change (because it's absolutely not related to the custom Button) but I think it's something in the MouseArea click event..
                  just a wild guess...

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved