qt - 带 slider 的 qml textedit

标签 qt qt4 qml

有谁知道如何创建可以使用 slider 换行的文本编辑器? 我尝试这样做,但我遇到了绑定(bind)循环的问题...

代码:

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

    } 

通过这种方式,我在 textEditBox 的右侧创建了一个 textEdit 和一个 slier。 slider 现在根据文本移动,但它( slider )不控制文本编辑框...我如何添加此操作? (以我的方式它带来了一个绑定(bind)循环)

最佳答案

如果按键事件与左右箭头匹配,也许您可​​以使用自定义插槽获取键盘按钮按下事件,即

请看这里:link对于 QWidget::grabKeyboard()

关于qt - 带 slider 的 qml textedit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5802085/

相关文章:

qt - 无法在 Qt 创建者中运行 Qt 示例 : The program has unexpectedly finished

c++ - QGraphicsView/QGraphicsScene渲染问题

c++ - QAbstractItemModel 对索引/父函数和数据函数感到困惑

c++ - 将 QML 事件传播到 C++

c++ - 将 Makefile 选项添加到 qtcreator 项目中

c++ - 共享库 QT 资源

c++ - 在 Qt Creator 中自动增加内部版本号

c++ - 在 windows7 : "no such file or directory" 上使用 mingw32 编译 Qt 4.8.5

c++ - 通过索引从 QML 中的 C++ 模型获取数据

listview - QML ListView 和 ListModel 索引