简体   繁体   English

Qt Design Studio 中 QML 的编辑器视图不正确

[英]Incorrect Editor View for QML in Qt Design Studio

This is Qt Design Studio, not Qt Quick Designer but it might be the same.这是 Qt Design Studio,不是 Qt Quick Designer,但它可能是一样的。

I made a component,我做了一个组件,

PaneWithTitle.qml

Column {
    id: column
    Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
    spacing: Style.paneTitleOffset

    property string title
    property alias inside: inner_space.sourceComponent

    DefaultText {
        text: qsTr(title)
    }

    Pane {
        id: pane

        background: Rectangle {
            color: "#283547"
            radius: Style.rectangleCornerRadius
        }

        Loader {
            id: inner_space
        }
    }
}

And I'm using it like this:我是这样使用它的:

PaneWithTitle {
    title: "Recovery"
    inside: ColumnLayout {
        id: rows

        TextFieldWithTitle {
            id: seed_input
            title: qsTr("Seed")
        }

        TextFieldWithTitle {
            id: password_input
            title: qsTr("Password")
        }

        RowLayout {
            id: columns

            Button {
                id: back_button
                text: qsTr("Back")
            }

            Button {
                id: confirm_button
                text: qsTr("Confirm")
            }
        }
    }
}

When I run it, it looks fine in Live Preview.当我运行它时,它在实时预览中看起来不错。 But inside the editor, size of the pane background is being 0.但是在编辑器中,窗格背景的大小为 0。

编辑器视图不匹配

Is there an elegant solution for this?有没有一个优雅的解决方案?

It's hard to find an absolute fix for that, looks like there is a bug in Form Editor items hierarchy, but you can at least slightly improve how it's shown.很难找到绝对的修复方法,看起来表单编辑器项目层次结构中存在错误,但您至少可以稍微改进它的显示方式。 If you can, please also submit your issue as a QDS bug report .如果可以,请将您的问题作为 QDS错误报告提交

You can remove Loader , replace Loader.sourceComponent with pane.contentItem and wrap PaneWithTitle.qml content with Item .您可以删除Loader ,用Loader.sourceComponent替换pane.contentItem并用Item包装PaneWithTitle.qml内容。 Code will look like that:代码将如下所示:

Item {
    id: root
    Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter

    property string title
    property alias inside: pane.contentItem

    Column {
        id: column
        anchors.fill: parent
        spacing: Style.paneTitleOffset

        Text {
            text: qsTr(title)
        }

        Pane {
            id: pane

            background: Rectangle {
                color: "#283547"
                radius: Style.rectangleCornerRadius
            }
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM