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. Help with text in lineEdit
QtWS25 Last Chance

Help with text in lineEdit

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 5 Posters 6.4k Views
  • 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.
  • D Offline
    D Offline
    doforumda
    wrote on last edited by
    #1

    I need help in my code. What i am trying to do is simply user enter some text in lineEdit then after clicking on the button it should get the text from lineEdit and display it in display rectangle.

    here is my code
    @
    import Qt 4.7

    Rectangle {
    width: 300
    height: 300
    Rectangle {
    id: lineEdit
    width: 200
    height: 50
    anchors.horizontalCenter: parent.horizontalCenter
    anchors.verticalCenter: parent.verticalCenter
    color: "lightblue"
    border.color: "green"
    TextInput {
    id: textField
    anchors.left: parent.left; y: 16
    anchors.right: parent.right
    //border.color: "green"
    text: "field 1"
    font.pixelSize: 32
    //color: focus ? "black" : "gray"
    }
    }
    Rectangle {
    id: button
    radius: 5
    width: lineEdit.width
    height: lineEdit.height
    border.color: "black"
    //color: "lightblue"
    x: 50; y: 180
    Text {
    id: buttonText
    anchors.horizontalCenter: parent.horizontalCenter
    anchors.verticalCenter: parent.verticalCenter
    text: "Click Me"
    font.pixelSize: 30
    }

        color: buttonRollOver.containsMouse ? "green" : "lightblue"
        MouseArea {
            id: buttonRollOver
            anchors.fill: parent
            hoverEnabled: true
        }
    }
    
    Rectangle {
        id: display
        border.color: "blue"
        width: lineEdit.width
        height: lineEdit.height
        x: button.x;
        y: 70
    }
    

    }
    @

    1 Reply Last reply
    0
    • C Offline
      C Offline
      cochise
      wrote on last edited by
      #2

      Well...

      Create a state for button when the property buttonText.text changes to textField.text and create a trigger "onClickerd" on buttonRollOver what chenges the state of buttonText

      http://cochise.tumblr.com

      1 Reply Last reply
      0
      • X Offline
        X Offline
        xsacha
        wrote on last edited by
        #3

        I have done this exact procedure a few times, so I'll show you how easy it is:
        Inside the buttonRollOver MouseArea:
        @onClicked: displaytext.text = textField.text@
        Simply move the text you have in textField to a text element inside display.

        Inside the display Rectangle:
        @
        Text {
        id: displaytext
        anchors.left: parent.left; y: 16
        anchors.right: parent.right
        font.pixelSize: 32
        }
        @
        A text element to display the text.

        • Sacha
        1 Reply Last reply
        0
        • K Offline
          K Offline
          kamalakshantv
          wrote on last edited by
          #4

          Just tried it out works fine.

          @import Qt 4.7

          Rectangle {
          width: 300
          height: 300
          Rectangle {
          id: lineEdit
          width: 200
          height: 50
          anchors.horizontalCenter: parent.horizontalCenter
          anchors.verticalCenter: parent.verticalCenter
          color: "lightblue"
          border.color: "green"
          TextInput {
          id: textField
          anchors.left: parent.left; y: 16
          anchors.right: parent.right
          //border.color: "green"
          text: "field 1"
          font.pixelSize: 32
          //color: focus ? "black" : "gray"
          }
          }
          Rectangle {
          id: button
          radius: 5
          width: lineEdit.width
          height: lineEdit.height
          border.color: "black"
          //color: "lightblue"
          x: 50; y: 180
          Text {
          id: buttonText
          anchors.horizontalCenter: parent.horizontalCenter
          anchors.verticalCenter: parent.verticalCenter
          text: "Click Me"
          font.pixelSize: 30
          }

              color: buttonRollOver.containsMouse ? "green" : "lightblue"
              MouseArea {
                  id: buttonRollOver
                  anchors.fill: parent
                  hoverEnabled: true
                 onClicked: showText.text = textField.text
              }
          }
          
          Rectangle {
              id: display
              border.color: "blue"
              width: lineEdit.width
              height: lineEdit.height
              x: button.x;
              y: 70
              Text {
                  id: showText
                  anchors.horizontalCenter: parent.horizontalCenter
                  anchors.verticalCenter: parent.verticalCenter
                  font.pixelSize: 30
              }
          
          }
          

          }
          @

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kamalakshantv
            wrote on last edited by
            #5

            How can we have a longer text entered wrapped inside the rectangle display.

            1 Reply Last reply
            0
            • 2 Offline
              2 Offline
              2beers
              wrote on last edited by
              #6

              [quote author="QtK" date="1291299310"]How can we have a longer text entered wrapped inside the rectangle display. [/quote]

              maybe you are looking for this: "wrapMode":http://doc.qt.nokia.com/4.7/qml-text.html#wrapMode-prop
              and you anchor the text field to the entire rectangle area

              1 Reply Last reply
              0
              • X Offline
                X Offline
                xsacha
                wrote on last edited by
                #7

                [quote author="QtK" date="1291299310"]How can we have a longer text entered wrapped inside the rectangle display. [/quote]
                Here's an example of how to do that:

                @import QtQuick 1.0

                FocusScope {
                width: 200; height: 200
                Rectangle {
                property int margins: 20
                x: margins; y: margins
                width: parent.width - margins2; height: parent.height - margins2
                border.color: "black"; border.width: 2; radius: 10
                color: "#23896363"
                Flickable {
                id: flick
                width: parent.width - 10; height: parent.height;
                clip: true
                function ensureVisible(r)
                {
                if (contentY >= r.y)
                contentY = r.y;
                else if (contentY+height <= r.y+r.height)
                contentY = r.y+r.height-height;
                }
                TextEdit {
                id: message
                x: 5;
                width: parent.width; height: parent.height;
                wrapMode: "WrapAtWordBoundaryOrAnywhere"
                onCursorRectangleChanged: flick.ensureVisible(cursorRectangle)
                font.pixelSize: 16
                }
                }
                }
                }@

                • Sacha
                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  kamalakshantv
                  wrote on last edited by
                  #8

                  Thanks its working.

                  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