qml текстедит со слайдером - PullRequest
       19

qml текстедит со слайдером

3 голосов
/ 27 апреля 2011

Кто-нибудь знает, как создать textEdit, который можно переносить с помощью ползунка? я пытался сделать это, но у меня возникла проблема с привязкой цикла ...

код:

Flickable
    {
        id: flick
        anchors.fill:parent
        contentWidth: edit.paintedWidth
        contentHeight: edit.paintedHeight
        clip: true
        interactive :false
        contentY: slider.y
        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: edit
            width: flick.width*0.9
            height: flick.height
            focus: true
            wrapMode: TextEdit.Wrap
            onCursorRectangleChanged: flick.ensureVisible(cursorRectangle)
            text: defaultText
            color: textColor
            font.family: fontFamily
            font.pointSize: fontSize
            font.bold: bold
            font.italic: italic
            font.overline: overline
            font.underline: underline
            horizontalAlignment: alignment
            selectByMouse:true

        }
    }

    Rectangle
    {
        id: container

        height: multiLineEdit.height
        width:multiLineEdit.width*0.1
        anchors.right:multiLineEdit.right
        anchors.top:multiLineEdit.top
        radius: 4
        opacity: 0.7
        smooth: true
        gradient: Gradient {
            GradientStop { position: 0.0; color: "gray" }
            GradientStop { position: 1.0; color: "white" }
        }

        Rectangle {
            id: slider

            property int value: Math.round(container.y*100/(slider.width-container.width))
            property int tmpVal: 0

            x: 1
            y: flick.visibleArea.yPosition * flick.height//1
            width: parent.width

            //The height will change according to the flickable area (the text area)
            height: (flick.visibleArea.heightRatio > 1) ? (container.height) :(flick.visibleArea.heightRatio*container.height)
            radius: 2
            smooth: true

            color:"black"

                   MouseArea {
                anchors.fill: parent
                drag.target: parent; drag.axis: Drag.YAxis
                drag.minimumY: 0; drag.maximumY: container.height - slider.height
            }
        }

    } 

таким образом я создаю textEdit и slier в правой части textEditBox. ползунок теперь перемещается в соответствии с текстом, но он (ползунок) не контролирует поле textEdit ... как я могу добавить это действие? (по-моему, это приносит обязательную петлю)

1 Ответ

0 голосов
/ 16 октября 2012

Может быть, вы могли бы получить событие нажатия кнопки клавиатуры с помощью специального слота, если ключевое событие совпало со стрелкой влево и вправо, т.е.

Пожалуйста, посмотрите здесь: ссылка для QWidget :: grabKeyboard ()

...