![](/img/trans.png)
[英]How to manage QML ScrollView navigation with respect to child QML TextEdit?
[英]How to update QML ScrollView navigation when navigating child QML TextEdit with up and down keys
我在ScrollView
有一個TextEdit
。 我怎樣才能實現邏輯,這樣的ScrollView
,當用戶按下向上或向下箭頭鍵,它會將文本以外的移動ScrollView
界限?
//qml
ScrollView {
id: palGenTextScrollView
property int scrollBarWidth: 15
anchors.fill: parent
MouseArea {
id: mouseArea
anchors.fill: parent
onWheel: {
if (wheel.modifiers & Qt.ControlModifier){
if (wheel.angleDelta.y > 0)
{
mainTextEdit.font.pixelSize++
}
else
{
mainTextEdit.font.pixelSize--
}
}
else{
wheel.accepted=false
}
}
}
TextEdit {
id: mainTextEdit
text: fileio.palFileText
font.family: "Courier"
wrapMode: TextEdit.Wrap
selectByMouse: true
//when going out of upward bounds: palGenTextScrollView.flickableItem.contentY--
//when going out of downward bounds: palGenTextScrollView.flickableItem.contentY++
}
}
您可以使用TextArea
來為您執行此操作。 如果您想烤自己的東西,請在詳細說明中查看TextEdit
文檔中的可輕彈示例。
請注意,TextEdit不會實現滾動,跟隨光標或其他特定於外觀的行為。 例如,要添加跟隨光標的可滑動滾動:
Flickable {
id: flick
width: 300; height: 200;
contentWidth: edit.paintedWidth
contentHeight: edit.paintedHeight
clip: true
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;
}
TextEdit {
id: edit
width: flick.width
height: flick.height
focus: true
wrapMode: TextEdit.Wrap
onCursorRectangleChanged: flick.ensureVisible(cursorRectangle)
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.