StackView中显示在Dialog上的转换问题

发布于 2025-01-20 11:42:08 字数 5638 浏览 3 评论 0原文

好吧,我在 Dialog 中的 StackView 遇到了问题。您可以在此示例中看到它。

也许我需要重写动画?

这是我的代码:

Dialog {
        id: settingDialog
        anchors.centerIn: parent
        width: 350
        height: parent.height / 1.1
        closePolicy: Dialog.NoAutoClose
        background: Rectangle {
            color: "darkgrey"
            border.color: "cyan"
            radius: 5
        }
        ColumnLayout {
            anchors.fill: parent
            spacing: 5
            ToolBar {
                Layout.fillWidth: true
                Layout.minimumHeight: 60
                background: Rectangle { color: "transparent" }
                RowLayout {
                    anchors.fill: parent
                    ToolButton {
                        id: tbBack
                        enabled: true
                        Layout.alignment: Qt.AlignHCenter
                        Layout.minimumWidth: 30
                        Layout.leftMargin: 10
                        background: Rectangle {
                            color: tbBack.hovered ? "darkcyan" : "transparent"
                            radius: parent.width
                        }
                        onClicked: stackViewSettings.pop()
                    }
                    Item { Layout.fillWidth: true }
                    ToolButton {
                        id: tbClose
                        Layout.alignment: Qt.AlignHCenter
                        Layout.minimumWidth: 30
                        Layout.rightMargin: 10
                        icon.source: "ADD YOUR ICO"
                        background: Rectangle {
                            color: tbClose.hovered ? "cyan" : "transparent"
                            radius: parent.width
                        }
                        onClicked: {
                            settingDialog.close()
                            stackViewSettings.pop()
                        }
                    }
                }
            }
            //
            StackView {
                id: stackViewSettings
                Layout.fillWidth: true
                Layout.fillHeight: true
                initialItem: Page {
                    background: Rectangle { color: noColor }
                    ColumnLayout {
                        anchors.fill: parent
                        spacing: 0
                        ListView {
                            id: listViewSettings
                            currentIndex: -1
                            interactive: false
                            spacing: 10
                            Layout.fillWidth: true
                            Layout.fillHeight: true
                            delegate: ItemDelegate {
                                height: 40
                                anchors {
                                    left: parent.left
                                    right: parent.right
                                }
                                highlighted: ListView.isCurrentItem
                                // Style of button
                                background: Rectangle {
                                    color: parent.hovered ? "#555e69" : "transparent"
                                    radius: 10
                                }
                                RowLayout {
                                    anchors.fill: parent
                                    spacing: 15
                                    // Image
                                    Rectangle {
                                        color: noColor
                                        Layout.minimumHeight: 30
                                        Layout.minimumWidth: 30
                                        Layout.leftMargin: 15
                                        Layout.alignment: Qt.AlignRight
                                        Image {
                                            anchors.fill: parent
                                            source: model.imageSource
                                        }
                                    }
                                    // Text
                                    Rectangle {
                                        color: "transparent"
                                        Layout.fillHeight: true
                                        Layout.minimumWidth: 150
                                        Layout.alignment: Qt.AlignLeft
                                        Text {
                                            anchors.verticalCenter: parent.verticalCenter
                                            text: model.title
                                            color: textColor
                                            font.pixelSize: 16
                                        }
                                    }
                                }
                                onClicked: stackViewSettings.push(model.source)
                            }
                            model: ListModel {
                                ListElement { title: "Change profile"; imageSource: "ADD YOUR ICO"; source: "ADD YOUR PAGE" }
                                ListElement { title: "Language"; imageSource: "ADD YOUR ICO"; source: "ADD YOUR PAGE" }
                            }
                        }
                    }
                }
            }
        }
    }

更新1:我认为我根本不应该在对话框上使用stackview。

更新 2:刚刚在 StackView 中添加了 clip: true ,它对我很有帮助。

Well, I've run into a problem with my StackView in Dialog. You can see it in this example.

Maybe I need to rewrite the animation?

Here is my code:

Dialog {
        id: settingDialog
        anchors.centerIn: parent
        width: 350
        height: parent.height / 1.1
        closePolicy: Dialog.NoAutoClose
        background: Rectangle {
            color: "darkgrey"
            border.color: "cyan"
            radius: 5
        }
        ColumnLayout {
            anchors.fill: parent
            spacing: 5
            ToolBar {
                Layout.fillWidth: true
                Layout.minimumHeight: 60
                background: Rectangle { color: "transparent" }
                RowLayout {
                    anchors.fill: parent
                    ToolButton {
                        id: tbBack
                        enabled: true
                        Layout.alignment: Qt.AlignHCenter
                        Layout.minimumWidth: 30
                        Layout.leftMargin: 10
                        background: Rectangle {
                            color: tbBack.hovered ? "darkcyan" : "transparent"
                            radius: parent.width
                        }
                        onClicked: stackViewSettings.pop()
                    }
                    Item { Layout.fillWidth: true }
                    ToolButton {
                        id: tbClose
                        Layout.alignment: Qt.AlignHCenter
                        Layout.minimumWidth: 30
                        Layout.rightMargin: 10
                        icon.source: "ADD YOUR ICO"
                        background: Rectangle {
                            color: tbClose.hovered ? "cyan" : "transparent"
                            radius: parent.width
                        }
                        onClicked: {
                            settingDialog.close()
                            stackViewSettings.pop()
                        }
                    }
                }
            }
            //
            StackView {
                id: stackViewSettings
                Layout.fillWidth: true
                Layout.fillHeight: true
                initialItem: Page {
                    background: Rectangle { color: noColor }
                    ColumnLayout {
                        anchors.fill: parent
                        spacing: 0
                        ListView {
                            id: listViewSettings
                            currentIndex: -1
                            interactive: false
                            spacing: 10
                            Layout.fillWidth: true
                            Layout.fillHeight: true
                            delegate: ItemDelegate {
                                height: 40
                                anchors {
                                    left: parent.left
                                    right: parent.right
                                }
                                highlighted: ListView.isCurrentItem
                                // Style of button
                                background: Rectangle {
                                    color: parent.hovered ? "#555e69" : "transparent"
                                    radius: 10
                                }
                                RowLayout {
                                    anchors.fill: parent
                                    spacing: 15
                                    // Image
                                    Rectangle {
                                        color: noColor
                                        Layout.minimumHeight: 30
                                        Layout.minimumWidth: 30
                                        Layout.leftMargin: 15
                                        Layout.alignment: Qt.AlignRight
                                        Image {
                                            anchors.fill: parent
                                            source: model.imageSource
                                        }
                                    }
                                    // Text
                                    Rectangle {
                                        color: "transparent"
                                        Layout.fillHeight: true
                                        Layout.minimumWidth: 150
                                        Layout.alignment: Qt.AlignLeft
                                        Text {
                                            anchors.verticalCenter: parent.verticalCenter
                                            text: model.title
                                            color: textColor
                                            font.pixelSize: 16
                                        }
                                    }
                                }
                                onClicked: stackViewSettings.push(model.source)
                            }
                            model: ListModel {
                                ListElement { title: "Change profile"; imageSource: "ADD YOUR ICO"; source: "ADD YOUR PAGE" }
                                ListElement { title: "Language"; imageSource: "ADD YOUR ICO"; source: "ADD YOUR PAGE" }
                            }
                        }
                    }
                }
            }
        }
    }

Upd 1: I don't think I should use the stackview on dialog at all.

Upd 2: Just added clip: true in the StackView and It helped me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

荆棘i 2025-01-27 11:42:08

你的问题只是一个剪辑问题。默认情况下,所有 QML 对象的 clip 设置为 false,但您可以打开它来解决您的问题:

StackView {
    ...
    clip: true
}

Your problem is just a clipping issue. By default all QML objects have clip set to false, but you can turn it on to solve your problem:

StackView {
    ...
    clip: true
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文