PDA

View Full Version : Cursor Position and Flickable Issue in TextEdit



beemaneni
10th March 2017, 16:31
Hi Guyz

I cannot place cursor in middle of the text inside TextEdit. i.e., i need to place cursor where ever i click on text. As i implemented MouseArea on TextEdit it does not allow me and i cannot successfully flick the content also as keyboard takes the precedence the moment i click on TextEdit field.

And how do i pass co-ordinates for flick(x,y) as i see it has to be between 0-1 ? As i click on Image on top or below flick needs to scroll up and down
Attached my code for ref:


Rectangle{
id: contactBox1
anchors{left: parent.left;leftMargin: 200;top: parent.top;topMargin: 200;bottom: parent.bottom;bottomMargin: 120}
width: 270
clip: true
color: "red"

Image {
id:topArrow
anchors{left: parent.left;leftMargin: parent.width/2-topArrow.width/2}
anchors{top: parent.top }
source: "WheelPickerArrow_Down.png"
visible: northAmericaFlick.contentHeight > northAmericaFlick.height
MouseArea{
anchors.fill: parent
onClicked: {
northAmericaFlick.flick(1,0.2)
}
}
}

Text{
id: northAmericaRegion
anchors{left: parent.left;leftMargin: 20;top: parent.top;topMargin: 20}
text: qsTr("North America:")
font.pixelSize: 26
}

Flickable{
id: northAmericaFlick
x: 20
anchors{top: parent.top;topMargin: 50 }
height: Qt.inputMethod.visible ? parent.height-230 : parent.height-100
width: parent.width
contentWidth: 230
contentHeight: northRegion.contentHeight
flickableDirection: Flickable.VerticalFlick
clip: true

function ensureNAVisible(r){
console.log("WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW "+r.x )
console.log("WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW "+r.y)
console.log("contentX "+ contentX )
console.log("contentY "+ contentY)
console.log("height "+ r.height)


if (contentX >= r.x)
contentX = r.x;
else if (contentX+width <= r.x+r.width)
contentX = r.x+r.width-width;
// if (contentY >= r.y)
// contentY = r.y;
// else if (contentY+height <= r.y+r.height)
// contentY = r.y+r.height-height;

contentY = r.y

}

TextEdit{
id: northRegion
text: "866-984-3766"
font.pixelSize:24
anchors.fill: parent
width: parent.width-30
color: "#8F8F8F"
clip: true
persistentSelection: true
wrapMode: Text.WrapAnywhere

onCursorRectangleChanged:
{
northAmericaFlick.ensureNAVisible(cursorRectangle)
}
}
}

Image {
id:bottomArrow1
anchors{left: parent.left;leftMargin: parent.width/2-bottomArrow1.width/2}
anchors{bottom: parent.bottom;bottomMargin: 5}
source:"WheelPickerArrow_Up.png"
visible: northAmericaFlick.contentHeight > northAmericaFlick.height
MouseArea{
anchors.fill: parent
onClicked: {
northAmericaFlick.flick(10,10) // how do i pass co-ordinates for flick ?
}
}
}

MouseArea{
anchors.fill: parent
propagateComposedEvents: true
onClicked: {
console.log("DDDDDDDDDDDDDDddd")
northRegion.forceActiveFocus()
northRegion.cursorVisible=true
Qt.inputMethod.show()
mouse.accepted=false
}
}

}


InputPanel {
id: inputPanel
z: 1
y: Qt.inputMethod.visible ? parent.height - inputPanel.height : parent.height
anchors.left: parent.left
anchors.right: parent.right
}

Can Anyone help me on this

Regards
Bala B

anda_skoa
11th March 2017, 11:14
Flickable.flick() is for starting a scrolling movement by specifiying velocities.

If you need to position a Flickable you'll need to change contentX and contentY.

Cheers,
_

beemaneni
12th March 2017, 00:54
Thank you..But how do i move flick line by line of textedit content. Should i consider current position and use line height of content ?

anda_skoa
12th March 2017, 12:12
Yes, that would be a thing I would try.

Cheers,
_