c++ - 如何在 rtl 对齐中打开右侧的子菜单?

标签 c++ qt qml qt-creator qtquick2

我有一个由项目和子菜单组成的菜单。项目的文本和标题应从右到左显示。我通过使用 LayoutMirroring.enabled = true 实现了这一点.

    Menu {
        id: right_menu
        property var rtl: true;

        MenuItem {
            text: "گزینه ۱"
            LayoutMirroring.enabled: true
            LayoutMirroring.childrenInherit: true
        }

        Menu {
            title: "تنظیمات"

            MenuItem {
                LayoutMirroring.enabled: true
                LayoutMirroring.childrenInherit: true
                text: "گزینه ۱"
            }

            MenuItem {
                LayoutMirroring.enabled: true
                LayoutMirroring.childrenInherit: true
                text: "گزینه ۱"
            }
        }

        delegate: MenuItem {
            LayoutMirroring.enabled: true
            LayoutMirroring.childrenInherit: true
        }
    }
这是输出:
wrong output
但是,这不是有效的输出,我想强制菜单在右侧而不是左侧打开子菜单。这是我正在寻找的输出:
expected output
我怎样才能做到这一点?

最佳答案

您可以使用 overlap属性将子菜单移动到您想要的位置。
请注意,如果菜单的位置太靠近窗口的左边缘或右边缘,它仍然会在相反的一侧打开。

Menu {
    id: right_menu
    property var rtl: true;

    MenuItem {
        text: "گزینه ۱"
        LayoutMirroring.enabled: true
        LayoutMirroring.childrenInherit: true
    }

    Menu {
        title: "تنظیمات"
        overlap: width * 2  // <<-- Shift the submenu over

        MenuItem {
            LayoutMirroring.enabled: true
            LayoutMirroring.childrenInherit: true
            text: "گزینه ۱"
        }

        MenuItem {
            LayoutMirroring.enabled: true
            LayoutMirroring.childrenInherit: true
            text: "گزینه ۱"
        }
    }

    delegate: MenuItem {
        LayoutMirroring.enabled: true
        LayoutMirroring.childrenInherit: true
    }
}

关于c++ - 如何在 rtl 对齐中打开右侧的子菜单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64625340/

相关文章:

c++ - 为什么 std::auto_ptr operator = 垃圾对象?

c++ - Lambdas 作为环境的闭包。 RIP寄存器的关键作用

c# - 保证CPU响应?

javascript - 从c++访问qml元素id

qt - "Bind"两个 QML CheckBox 在一起,确保它们的状态始终相同

c++ - 如何在 C++ 中推断函数参数类型?

qt - 如何防止 QWebEngineView 将注意力集中在 setHtml(...) 和 load(...) 调用上?

c++ - 如何以交互方式调整 QGraphicsObject 的大小?

c++ - eclipse 中使用 qt 插件的 qt gui 项目

qt - qt 快速 QML 应用程序的自定义样式页面(如 HTML 和 CSS)