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. Problems when using a Rectangle and a Text
Forum Updated to NodeBB v4.3 + New Features

Problems when using a Rectangle and a Text

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 664 Views 2 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.
  • tomyT Offline
    tomyT Offline
    tomy
    wrote on last edited by
    #1

    Hi all,

    I don't know why the text here isn't shown on the rectangle:

    MyButton.qml:

    import QtQuick 2.9
    
    Item {
      property string text: myText.text
    
        Rectangle {
           width: 70; height: 25
           color: "lightsteelblue"
         }
    
        Text {
            id: myText
            width: 40; height: 20
            anchors.centerIn: parent
            color: "blue"
            font.bold: true
            font.pixelSize: 15
        }
    }
    

    main.qml:

    import QtQuick 2.9
    import QtQuick.Window 2.2
    
    Window {
        visible: true
        width: 600
        height: 500
        title: qsTr("QML Test")
        color: "silver"
    
        Rectangle {
            id: container
            width: 400; height: 300
            color: "cadetblue"
    
            MyButton {
                id: start
                text: "START"
                x: 200
                y: 100
            }
        }
    }
    

    The problem might be very subtle but at this moment I can't find it! :(

    I also used this version of Mybutton:

    import QtQuick 2.9
    
     Rectangle {
        width: 70; height: 25
        color: "lightsteelblue"  
        property string text: myText.text
    
        Text {
            id: myText
            width: 40; height: 20
            anchors.centerIn: parent
            color: "blue"
            font.bold: true
            font.pixelSize: 15
        }
    }
    

    But no change in the result!
    Also tried: Clean All, Run qmake, Rebuild all
    :(

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mostefa
      wrote on last edited by mostefa
      #2

      @tomy said in Problems when using a Rectangle and a Text:

      property string text: myText.text

      Hi @tomy

      What if you change this line

      property string text: myText.text
      

      to

      property string text
      

      And the content of myButton to something like this :

      MyButton {
                id: start
                Component.onCompleted:
                {
                    start.text = "start"
                }
      
                x: 200
                y: 100
            }
      

      Also your Text element must look to something like this:

      ```
      
      Text {
              id: myText
              text: root.text
              anchors.centerIn: parent
              color: "white"
              font.bold: true
              font.pixelSize: 15
          }
      

      Have a look at this link

      tomyT 1 Reply Last reply
      1
      • M mostefa

        @tomy said in Problems when using a Rectangle and a Text:

        property string text: myText.text

        Hi @tomy

        What if you change this line

        property string text: myText.text
        

        to

        property string text
        

        And the content of myButton to something like this :

        MyButton {
                  id: start
                  Component.onCompleted:
                  {
                      start.text = "start"
                  }
        
                  x: 200
                  y: 100
              }
        

        Also your Text element must look to something like this:

        ```
        
        Text {
                id: myText
                text: root.text
                anchors.centerIn: parent
                color: "white"
                font.bold: true
                font.pixelSize: 15
            }
        

        Have a look at this link

        tomyT Offline
        tomyT Offline
        tomy
        wrote on last edited by tomy
        #3

        @mostefa

        property string text
        Text {
                id: myText
                text: root.text
                anchors.centerIn: parent
                color: "white"
                font.bold: true
                font.pixelSize: 15
            }
        

        I used it. Thanks.
        I can't mark your answer as the correct answer. I hope some moderator with top privileges does it.

        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