2016-11-04 4 views
1

나는 ScrollView 안에 TextEdit을 가지고 있습니다. 사용자가 위 또는 아래 화살표 키를 눌렀을 때 ScrollView 범위를 넘어서 텍스트를 이동할 때 ScrollView이 움직 이도록 논리를 구현할 수 있습니까?위 키 및 아래 키를 사용하여 하위 QML 텍스트 편집을 탐색 할 때 QML 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++ 
    } 
} 

답변

2

정확히 일치하는 TextArea을 사용할 수 있습니다. 직접 굽고 싶다면 상세한 설명에서 TextEdit의 문서에있는 flickable 예제를 살펴보십시오.

텍스트 편집기는 스크롤 또는 커서 다음에 모양이나 느낌과 관련된 다른 동작을 구현하지 않습니다. 예를 들어 커서 뒤의 스크롤 가능한 스크롤을 추가하려면 다음을 입력하십시오.

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) 
     } 
    }