【问题标题】:QML TableView: Binding loop detected for property "__scrollBarTopMargin"QML TableView:检测到属性“__scrollBarTopMargin”的绑定循环
【发布时间】:2019-10-21 16:34:44
【问题描述】:

我只是想在我的 QML 文件中创建一个 TableView,就像这样 -

TableView {
        id: resultListTableView
        anchors.fill: parent
        rowDelegate: Rectangle {
            color: "#D3D3D3"
            height: 30
        }

        itemDelegate: Rectangle {
            width: 100
            height: 50
            border.color: "#000000"
            border.width: 1
            Text {
                id: textItem
                text: styleData.value
                anchors.fill: parent
                verticalAlignment: Text.AlignVCenter
                horizontalAlignment: Text.AlignHCenter
                elide: Text.ElideRight
            }
        }

        headerDelegate: Rectangle {
            height: textItem.implicitHeight * 1.2
            width: textItem.implicitWidth
            color: "lightsteelblue"
            Text {
                id: textItem
                anchors.centerIn: parent
                text: styleData.value
                elide: Text.ElideRight
            }
        }

        TableViewColumn {
            role: "file"
            title: "File"
            width: resultListTableView.viewport.width * 0.3
            movable: false
            resizable: false
        }
        TableViewColumn {
            role: "type"
            title: "Type"
            width: resultListTableView.viewport.width * 0.2
            movable: false
            resizable: false
        }
        TableViewColumn {
            role: "size"
            title: "Size"
            width: resultListTableView.viewport.width * 0.2
            movable: false
            resizable: false
        }
        TableViewColumn {
            role: "path"
            title: "Path"
            width: resultListTableView.viewport.width * 0.3
            movable: false
            resizable: false
        }

        model: ResultListDataModel {}
        onDoubleClicked: {
            const element = model.get(row)
            console.log("Downloading file ", element.file, "of size", element.size)
        }
    }

此组件是 TabView 的一部分,并在单击相应选项卡时显示。但是,当单击选项卡时,我随机收到一个绑定循环警告:

QML TableView: Binding loop detected for property "__scrollBarTopMargin"

我没有做任何可能导致这个绑定循环的事情,所以我想知道问题出在哪里。有人知道这里发生了什么吗?

【问题讨论】:

    标签: qt qml


    【解决方案1】:

    纯粹的推测,没有方便的 Qt 开发环境,但我猜视口取决于列的宽度,而列的宽度现在取决于视口。

    破解为列设置宽度的四行将很快证明或反驳。

    如果这个疯狂的猜测不起作用,请从这里的来源https://github.com/qt-creator/qt-creator/blob/master/tests/auto/qml/codemodel/importscheck/005_compositeQmlCopyAndCpp/QtQuick/Controls/TableView.qml,我看到__scrollBarTopMargin: (__style && __style.transientScrollBars || Qt.platform.os === "osx") ? headerrow.height : 0

    您可能会考虑修改您的标头委托,看看是否可以消除警告。

    哦,哇,ID 重复很微妙。正如您自己所说,重复的 ID 似乎与您的尺寸混淆了。希望这是您收到的第一个警告,而不是您实际收到的疯狂警告。

    【讨论】:

    • 看来你是对的。我将对其进行更多测试以确认然后接受您的答案。谢谢!
    • 问题似乎是 headerDelegate 的高度和宽度属性,虽然我不完全明白为什么。如果我删除高度和宽度属性,它确实有效,但标题的外观会完全混乱。如您所见,我对 QML 没有太多经验。有什么想法吗?
    • 在黑暗中的另一个镜头,但我想知道是否明确设置高度和宽度而不是设置代理的隐含高度和宽度会导致这种情况。如果您切换这些行以设置隐含的高度和宽度,您是否会在没有警告的情况下获得所需的行为?
    • 您的意思是implicitHeight 和implicitWidth 吗?如果是,那也不行。
    • 我的意思是implicitHeight 和implicitWidth。伙计,标题代表的例子很少而且相差甚远。我想知道尝试从委托中设置矩形的高度是否是正确的方法,但我无法指出示例或反例。我在 QtQuick 中也有一年半的时间。如果您根本不设置这些属性,我假设在视觉上出现了问题?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-17
    • 1970-01-01
    • 1970-01-01
    • 2015-10-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多