admin管理员组文章数量:1199963
I get this message in QtCreator output:
file:///C:/.../foo.qml:428:5: QML PopupWarning: Binding loop detected for property "implicitHeight":
qrc:/qt-project/imports/QtQuick/Controls/FluentWinUI3/Dialog.qml:16:5
"PopupWarning.qml":
import QtQuick
import QtQuick.Controls
Dialog {
parent: Overlay.overlay
property alias text : dialogText.text
anchors.centerIn: parent
width: parent.width/2
dim: true
modal: true
//implicitHeight: dialogText.height
Text {
id: dialogText
width: parent.width
font.pointSize: 15
}
}
The problem is that I cannot specify exact height, because the Text inside dialog may be of various lengths. The same with the title. Also, standardButtons may or may not be present. And I would like to keep the Dialog size as small as possible. The code works, but I would like to prevent all warnings.
Question: is there some way to calculate the height of the Dialog/Popup in this situation?
I get this message in QtCreator output:
file:///C:/.../foo.qml:428:5: QML PopupWarning: Binding loop detected for property "implicitHeight":
qrc:/qt-project.org/imports/QtQuick/Controls/FluentWinUI3/Dialog.qml:16:5
"PopupWarning.qml":
import QtQuick
import QtQuick.Controls
Dialog {
parent: Overlay.overlay
property alias text : dialogText.text
anchors.centerIn: parent
width: parent.width/2
dim: true
modal: true
//implicitHeight: dialogText.height
Text {
id: dialogText
width: parent.width
font.pointSize: 15
}
}
The problem is that I cannot specify exact height, because the Text inside dialog may be of various lengths. The same with the title. Also, standardButtons may or may not be present. And I would like to keep the Dialog size as small as possible. The code works, but I would like to prevent all warnings.
Question: is there some way to calculate the height of the Dialog/Popup in this situation?
Share Improve this question edited Jan 22 at 19:34 Daniel asked Jan 22 at 19:32 DanielDaniel 134 bronze badges 4- There's a potential binding loop since if you were to enable wrapMode, the text's height would be influence by the Dialog geometry but the Dialog geometry is being influence by the Text geometry. Instead of dialogText, perhaps you can get height from TextMetrics? – Stephen Quan Commented Jan 22 at 20:43
- Tried with TextMetrics but without success. But you have motivated me to calculate it other way ;) – Daniel Commented Jan 23 at 10:20
- You don't need TextMetrics, since Text will tell its required dimensions in its implicitWidth and implicitHeight variables. In the Text's case, the implicitWidth and implicitHeight properties are read only. I don't know what do you want to achieve here exacly, like do you want the Dialog to have a size that surely fits the Text? If yes, set the dialog size like this: "width: dialogText.implicitWidth and height: dialogText.implicitHeight" – Ponzifex Commented Jan 23 at 22:19
- @Ponzifex Unfortunately it doesn't work that way. One need to calulate for header height, footer height and also space around text. Look at my answer below – Daniel Commented Jan 24 at 11:25
1 Answer
Reset to default 0I found a way to calculate the height in my case:
height: (standardButtons != Dialog.NoButton) ? header.height + footer.height + dialogText.height + 35 : header.height + dialogText.height + 35
The value of 35 comes from this equation (when you did not specify the dialog height):
Component.onCompleted: console.log(height - dialogText.height)
Visually it looks exactly the same, even if I change the font size
本文标签: qtQML Binding loop detected for property quotimplicitHeightquotStack Overflow
版权声明:本文标题:qt - QML: Binding loop detected for property "implicitHeight": - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738543237a2095908.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论