QML ScrollView 在使用自定义 ScrollBar 时不会删除默认 ScrollBar。为什么?怎么解决这个问题?

问题描述 投票:0回答:1

使用QML 5.15,带有自定义ScrollBar的ScrollView不会隐藏默认滚动条。参见图片,右上角的白点。怎么解决这个问题?

来源:

import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15

Window {
  id: window

  width: 640
  height: 480
  visible: true
  title: qsTr("Hello ScrolView and ScrollBar")
  color: "blue"

  ScrollView {
    id: scroll_view
    width: parent.width - 40
    height: parent.height

    TextInput {
      id: text_input
      anchors.fill: parent
      text: "A very large text but this will be enough to get the picture."
      color: "white"
      readOnly: true
      selectByMouse: true
      width: parent.width
      height: parent.height
    }
    ScrollBar.vertical: ScrollBar {
      policy: "AlwaysOn"
      parent: scroll_view
      x: text_input.width
      width: 20
      height: scroll_view.availableHeight
    }
  }
}

使用策略AlwaysOff隐藏自定义滚动条,但不隐藏默认滚动条。

qml scrollview scrollbar
1个回答
0
投票

对于

ScrollView
,您不需要实例化一个新的
ScrollBar
,对于
ScrollBar.vertical
,已经有一个,即代替

ScrollBar.vertical: ScrollBar {

ScrollBar.vertical {
© www.soinside.com 2019 - 2024. All rights reserved.