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. Reducing bindings fail
Qt 6.11 is out! See what's new in the release blog

Reducing bindings fail

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 3 Posters 410 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.
  • R Offline
    R Offline
    RobM
    wrote on last edited by RobM
    #1

    I am trying to reduce the amount of property bindings on this small bit of code used as an example but I am running into a problem. For some reason, the text is not showing. Here is the code:

    import QtQuick 2.12
    import QtQuick.Controls 2.5
    import QtQuick.Window 2.0
    
    ApplicationWindow
    {
      id: root
      visible: true
      width: 640
      height: 480
      
      //  Rectangle
      //  {
      //      id: content
      //      anchors.centerIn: parent
      //      width: theText.width + 10
      //      height: theText.height + 10
      //      color: mouseArea.pressed ? "green" : "blue"
      //       Text
      //      {
      //          id: theText
      //          anchors.centerIn: parent
      //          text: mouseArea.pressed ? "Technologies" : "Jet"
      //      }
      //       MouseArea
      //      {
      //          id: mouseArea
      //          anchors.fill: parent
      //      }
      //  }
    
      Rectangle
      {
        id: content
        anchors.centerIn: parent
        width: theText.width + 10
        height: theText.height + 10
    
        Text
        {
          id: theText
          anchors.centerIn: parent
        }
        MouseArea
        {
          id: mouseArea
          anchors.fill: parent
          onPressedChanged:
          {
            if (pressed)
            {
              content.color = "blue";
              theText.text = "Jet";
            }
            else
            {
              content.color = "green";
              theText.text = "Technologies";
            }
          }
        }
      }
    }
    

    note that in the commented version everything works as expected. However, when I run the uncommented version the text doesn't show up unless I assign a value to theText's text property directly, why is that?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DeltaSim
      wrote on last edited by
      #2
      This post is deleted!
      1 Reply Last reply
      0
      • GrecKoG Offline
        GrecKoG Offline
        GrecKo
        Qt Champions 2018
        wrote on last edited by
        #3

        For my curiosity , why do you want to do that?

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DeltaSim
          wrote on last edited by
          #4

          Hi Rob,

          The problem is that you did not initialized your rectangle's color and text.
          At startup your rectangle is white with no text, when you click on the mouse area the text show up with a color.

          But as said GrecKo it seems strange to do that.

          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