TrayMenu: fix tray menu allocation per tray item

This commit is contained in:
Ly-sec
2025-11-15 22:32:40 +01:00
parent f28452a258
commit ebe50561a8
+19 -2
View File
@@ -24,8 +24,8 @@ PopupWindow {
property bool shouldLoadMenu: false
property var menuItems: []
// Derive menu from trayItem (only used for non-submenus)
readonly property QsMenuHandle menu: isSubMenu ? null : (trayItem ? trayItem.menu : null)
// Menu can be set directly (for submenus) or derived from trayItem
property var menu: null
// Compute if current tray item is pinned
readonly property bool isPinned: {
@@ -86,6 +86,7 @@ PopupWindow {
const values = opener.children.values
if (values && values.length > 0) {
root.menuItems = [...values]
Logger.i("TrayMenu", "Loaded " + root.menuItems.length + " menu items")
} else {
Logger.warn("TrayMenu", "opener.children.values is empty")
}
@@ -104,10 +105,18 @@ PopupWindow {
return
}
// IMPORTANT: Set the menu BEFORE loading items
if (!isSubMenu && trayItem && trayItem.menu) {
menu = trayItem.menu
}
anchorItem = item
anchorX = x
anchorY = y
// Reset menu items to force reload with new menu
menuItems = []
// Trigger menu loading only when showing
shouldLoadMenu = true
@@ -149,6 +158,14 @@ PopupWindow {
QsMenuOpener {
id: opener
menu: root.menu
onMenuChanged: {
// When menu changes, reset and reload
if (root.shouldLoadMenu) {
root.menuItems = []
Qt.callLater(() => root.loadMenuItemsSafely())
}
}
}
Rectangle {