[英]How to open sub-menu on right hand side in rtl alignments?
我有一個由項目和子菜單組成的菜單。 項目的文本和標題應從右到左顯示。 我通過使用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
}
}
這是輸出:
但是,這不是有效的輸出,我想強制菜單在右側而不是左側打開子菜單。 這是我正在尋找的輸出:
我怎樣才能做到這一點?
您可以使用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
}
}
感謝@JarMan,如果人們只想旋轉菜單(就我而言),他的解決方案可以解決問題。 但是對於從右到左的語言來說,更好的解決方案是讓你的整個應用從右到左; 因為在從右到左的語言中,一切都應該以這種方式進行。 為此,您可以在項目的main.cpp
文件中添加以下行。
app.setLayoutDirection(Qt::rightToLeft);
然后在任何其他項目或窗口中,添加以下行:
LayoutMirroring.enabled: Qt.application.layoutDirection == Qt.RightToLeft
LayoutMirroring.childrenInherit: Qt.application.layoutDirection == Qt.RightToLeft
我懷疑 LayoutMirroring 導致您的子菜單在錯誤的位置彈出。 不要使用 LayoutMirroring 來實現您想要的文本格式,而是使用自定義文本組件並在那里編輯文本的對齊方式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.