QML中Flickable中ScrollView中的ScrollBar

问题描述

我创建了一个 TextArea,它位于高度 78px 宽度 288px 的 Rectangle 内。 对于滚动,我使用的是 Flickable 并且我有一个具有特定高度、宽度、颜色的自定义滚动条,所以我使用了 ScrollBar.vertical:ScrollBar{}

1) 我的问题是,当我运行应用程序时,它看起来不错,但有点僵硬,就像它的 snapMode:ScrollBar.SnapAlways 不起作用,policy:Scrollbar.AsNeeded 我尝试了 here 中的代码,即文档中的代码

2) 接下来是 press 属性在这里也没有帮助我。

分享了我在代码中使用的代码片段。请看看这个。

Rectangle{
id:parentrect
height:78
width:288
...

 Flickable {
    id:flickitem
    width: parent.width
    height:parent.height
    contentWidth: textarea.width
    contentHeight:textarea.height
    anchors{
    left: parent.left
    right: parent.right
    leftMargin: 12
    }
    anchors.fill: parent
    //interactive: true
    boundsMovement: Flickable.FollowBoundsBehavior
    boundsBehavior: Flickable.StopAtBounds
    flickableDirection: Flickable.VerticalFlick
    clip: true
    ScrollBar.vertical: ScrollBar {
        id: control
        policy: {

            if(textarea.height>parentrect.height)
                ScrollBar.AsNeeded
            else
                ScrollBar.AlwaysOff
      }

        snapMode: ScrollBar.SnapAlways
        anchors{
            right: flickitem.right
            top:flickitem.top
            bottom: flickitem.bottom
            rightMargin: 1
            topMargin: 1
            bottomMargin: 1
        }
        opacity: rTaScrollBarOpacity
        contentItem: Rectangle {
            implicitWidth: rTaScrollRectWidth
            implicitHeight: rTaScrollRectHeight
            radius:5.5
            color:{
            if(iThemeType===Defaults.Theme.Light)
               control.pressed? palette.edsBlack:palette.edsBlack
            else
              control.pressed? palette.edsGray1000: palette.edsGray1000
            }
        }

    }
TextArea.flickable:  TextArea {
        id:textarea
            ....

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)