如何避免约束力循环设定时填?

0

的问题

我想要更新的填充的一个滚动型的,如果有一个滚动可见的,但在另一方面,可见度的滚动是依赖于高度宽容的内的滚动条,这改变了当的填充的变化。 以下原因导致的一种结合循环:

ScrollView {
  id: control
  rightPadding: Scrollbar.vertical.visible ? Scrollbar.vertical.width : 0
   ....


  ScrollBar.vertical: ScrollBar {
    parent: control
    visible: control.height < height
   ...
  }
}

我如何可以实现这种没有约束力循环? 感谢

qml qt qtquickcontrols2
2021-11-15 14:43:32
1

最好的答案

0

我不能让你的代码frag工作-它看起来像你的代码应该依赖于内容你的 ScrollView但这不是在代码中包含frag,它可能缺少其他一些参考文献。

无论如何,我建议在接近这有点不同-改变 ScrollView's的内容的宽度的基础上是否 ScrollBar 是可见的。 我也设置 ScrollBar 政策而不是知名度。 我已经创建了一个全面的例子可以在其中添加或删除内容采用一个滑动对示范:

import QtQuick 2.15
import QtQuick.Layouts 1.12
import QtQuick.Controls 2.12

ApplicationWindow {
    id: root
    visible: true
    height: 500
    width: 500

    ColumnLayout {
        anchors {
            fill: parent
        }

        Slider {
            // use slider to add delegates to the ScrollView to toggle the scroll bar visibility
            id: slider
            to: 20
        }

        ScrollView {
            id: scroll
            Layout.fillHeight: true
            Layout.fillWidth: true
            ScrollBar.vertical.policy: scrollBarVisible ? ScrollBar.AlwaysOn : ScrollBar.AlwaysOff

            property bool scrollBarVisible: scroll.contentHeight > scroll.height

            ColumnLayout {
                width: scroll.scrollBarVisible ? scroll.width - scroll.ScrollBar.vertical.width : scroll.width // change the width of the 

                Repeater {
                    model: slider.value
                    delegate: Rectangle {
                        color: "tomato"
                        Layout.fillWidth: true
                        Layout.preferredHeight: 150
                    }
                }
            }
        }
    }
}

有一点要注意,虽然-你的 ScrollView 内容不能有其高度依赖于它的宽度,例如,如果内容有一些 Text 包装,如果没有足够宽,从而导致它获得更高当宽度下降。 这将回到无限的环境。

2021-11-16 04:25:42

谢谢你的评论。 这正是我有内容-a textArea用词包裹,其中高度依赖于宽度。 有没有办法我可以避免递归在这种情况下?
Denis

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................