次の簡単な例を実行している場合:
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Window 2.2
import QtQuick.Layouts 1.3
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Popup {
width: 100
visible: true
contentItem: ColumnLayout {
Rectangle {
Layout.fillWidth: true
implicitHeight: 50
color: "red"
}
Text {
Layout.fillWidth: true
text: "some very very very very very very very very very very very very long text"
wrapMode: Text.WordWrap
}
}
}
}
次の警告が表示されます:qrc:/main.qml:12:5: QML Popup: Binding loop detected for property "contentHeight"
そしてPopup
高さを誤って検出します:
多分に接続されている問題Text
のimplicitHeight
それは上のいくつかの依存関係を持っているので、ColumnLayout
S 'implicitHeight
が、私は理由を理解することはできません。
バインディングループがどのように表示され、それを解決する方法を誰かが私に説明できますか?
解決:
Popup {
width: 100
visible: true
contentItem: Column {
Rectangle {
width: parent.width
implicitHeight: 50
color: "red"
}
Text {
width: parent.width
text: "some very very very very very very very very very very very very long text"
wrapMode: Text.WordWrap
}
}
}
警告について:バグのように見えますが、そうではないと思います。2つのrectsにその警告がない場合。
またLayout.fillWidth: true
、テキストの削除もありません。したがって、テキストの高さにはColumnLayoutの幅が必要であり、ColumnLayoutはテキストの高さだけ高さを展開します。2つのコンポーネントが互いのサイズを必要とするというパラドックスのように感じます。
更新:
Popup {
width: 100
visible: true
contentItem: ColumnLayout {
width: parent.width
Rectangle {
Layout.fillWidth: true
implicitHeight: 50
color: "red"
}
Text {
Layout.fillWidth: true
text: "some very very very very very very very very very very very very long text"
wrapMode: Text.WordWrap
}
}
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加