|
10Qter豆
大家好!
目前遇到一个问题,需要利用Qml的控件来实现短信的编辑功能(主要是如何对文本内容的选择)。比如像android短信的编辑功能一样,长按弹出菜单,然后通过控制光标来选择内容。- Flickable { id: flick anchors.left: addinfo.right anchors.leftMargin: 20 anchors.right: parent.right anchors.rightMargin: 20 anchors.bottom: infofriengandcommon.top anchors.bottomMargin: 10 width: parent.width height: textInput.height contentWidth: textInput.contentWidth contentHeight: textInput.contentHeight clip: true boundsBehavior:Flickable.StopAtBounds flickableDirection: Flickable.VerticalFlick onMovementStarted:start() onMovementEnded:end()
- function ensureVisible(r) { 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; }
- function start(){ pressormove = false; console.log("==1======start============")
- }
- function end(){ console.log("==2======end==============")
- }
- TextEdit { id: textInput// anchors.top: flick.top// anchors.topMargin: 10// anchors.left: parent.left// anchors.leftMargin: 20// anchors.right: parent.right// anchors.rightMargin: 20// anchors.bottom: parent.bottom// anchors.bottomMargin: 10 height: if( textInput.lineCount < 3) 100 else if( textInput.lineCount*50 == 150) 150 else 200 width: flick.width font.pixelSize: 32 focus: false wrapMode: Text.Wrap onCursorRectangleChanged: flick.ensureVisible(cursorRectangle)
- }
- MouseArea{ id: mouid enabled: textInput.focus === true anchors.fill: parent onPressed: {
- pressorhold = false; console.log("==1======onPressed========" + onPressed) if( Qt.inputMethod.visible === false) { textInput.focus = false; textInput.focus = true; } if(pressormove){ textInput.cursorPosition = textInput.positionAt( mouid.mou**, mouid.mouseY) }
- mpressx = mouid.mou** mpressy = mouid.mouseY }
- onPositionChanged: { if(pressorhold) textInput.select(textInput.positionAt(mpressx,mpressy),textInput.positionAt(mou**,mouseY))
- }
- onPressAndHold: { pressorhold = true; //toast.setMessage(qsTr("安全短信密码设置成功!")) console.log("==1======pressorhold========" + pressorhold)
- pressandhold() }
- onCanceled:{ console.log("===2=====onCanceled========" + onCanceled) }
- onReleased: { pressormove = true; console.log("===2=====pressormove========" + pressormove)// if(pressorhold){// pressandhold()// } } }
- Keys.onReleased: { if( event.key === Qt.Key_Menu) { menuSignal(); } } }
复制代码 |
最佳答案
查看完整内容
帮你换了个发帖格式,代码要用这个框框起来就不会位置错乱了,不过你贴上来时候已经乱了,我就不帮你整理,你看到这里再重新编辑一下吧。
另外,看起来你的qml基础还可以的,textinput或textarea熟悉一下自带的api,你只需要多发挥一些想象力,再参考一下别的手机是怎么做的就好。
|