help with text in lineEdit
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
- }
- }
7 replies
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.
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
- }
- }
- }
How can we have a longer text entered wrapped inside the rectangle display.
maybe you are looking for this: wrapMode [doc.qt.nokia.com]
and you anchor the text field to the entire rectangle area
How can we have a longer text entered wrapped inside the rectangle display.
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 - margins*2; height: parent.height - margins*2
- 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
- }
- }
- }
- }
You must log in to post a reply. Not a member yet? Register here!




