Help with text in lineEdit
-
wrote on 25 Nov 2010, 12:19 last edited by
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.7Rectangle {
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 }
}
@ -
wrote on 25 Nov 2010, 13:58 last edited by
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
-
wrote on 2 Dec 2010, 01:53 last edited by
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. -
wrote on 2 Dec 2010, 12:24 last edited by
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 } }
}
@ -
wrote on 2 Dec 2010, 14:15 last edited by
How can we have a longer text entered wrapped inside the rectangle display.
-
wrote on 2 Dec 2010, 14:30 last edited by
[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 -
wrote on 2 Dec 2010, 14:39 last edited by
[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
}
}
}
}@ -
wrote on 2 Dec 2010, 14:48 last edited by
Thanks its working.
1/8