代码之家  ›  专栏  ›  技术社区  ›  TSG

无法滚动的滚动视图

  •  0
  • TSG  · 技术社区  · 3 年前

    我有一个流量,远远超过屏幕底部。所以我把它包在了ScrollView中;然而,我就是不能让它工作。

    一个(小)问题是,将contentWidth设置为parent.width以外的任何值都会导致流不显示任何内容。我不应该设置contentWidth/contentHeight,因为scrollView只包含一个项目。(但不设置这些会导致scrollView为空)。

    主要问题是视图不可滚动(一旦我显示了内容)。我可以在底部看到内容截断,但我无法用鼠标上下拖动它,也不会出现滚动条。怎么了?

    Rectangle {
        anchors {
            top: buttons.bottom
            left: parent.left
            right: parent.right
            bottom: parent.bottom
        }
        ScrollView {
            clip: true
            contentHeight:  gatewayFlow.implicitHeight
            contentWidth:  parent.width // availableWidth // gatewayFlow.implicitWidth
            Flow {
                id: gatewayFlow
                anchors.fill: parent
                spacing: 10
                Gateway { }
                Gateway { }
                Gateway { }
                Gateway { }
                Gateway { }
                Gateway { }
                Gateway { }
                Gateway { }
                Gateway { }
            }  // Flow
        } // ScrollView
    }  // Rectange
    
    0 回复  |  直到 3 年前
        1
  •  0
  •   David K. Hess    3 年前

    问题是,如果您没有对ScrollView进行其他约束,则默认情况下,ScrollView的宽度和高度会根据内容大小进行增长和收缩。如果宽度和高度与内容宽度和高度匹配,你自然不会得到任何滚动。

    将此添加到ScrollView中以约束它并获得内容的实际滚动行为:

        anchors.fill: parent