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
Add a comment  | 

1 Answer 1

Reset to default 0

I 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