3
votes

Does anyone know how to create a textEdit that can wrap using a slider? i tried to do it but i got a problem with binding loop...

code:

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

    } 

in this way i create a textEdit and a slier at the right side of the textEditBox. the slider is now move according to the text, but it(the slider) doe's not control the textEdit box... how i can add this action? (in my way it bring a binding loop)

1
Can you post some code sample and describe the problem you refered in your question? - bruno
i don't wan't it to be scroll with the mouse, ONLY with the slider... - dan

1 Answers

0
votes

Maybe you could grab keyboard button press event with a custom slot if key event match left and right arrow i.e.

Please take a look here: link for QWidget::grabKeyboard()