diff --git a/UM/Qt/qml/UM/Menu.qml b/UM/Qt/qml/UM/Menu.qml index 30538cbcf..264fe2a86 100644 --- a/UM/Qt/qml/UM/Menu.qml +++ b/UM/Qt/qml/UM/Menu.qml @@ -10,19 +10,6 @@ Menu // This is a work around for menu's not actually being visual items. Upon creation, a visual item is created // The work around is based on the suggestion given in https://stackoverflow.com/questions/59167352/qml-how-to-hide-submenu property bool shouldBeVisible: true - onParentChanged: handleVisibility() - function handleVisibility() - { - if(parent) - { - root.parent.visible = shouldBeVisible - root.parent.height = shouldBeVisible ? UM.Theme.getSize("menu").height : 0 - root.width = shouldBeVisible ? Qt.binding(setWidth) : 0 - } - } - - Component.onCompleted: handleVisibility() - onShouldBeVisibleChanged: handleVisibility() // Automatically set the width to fit the widest MenuItem // Based on https://martin.rpdev.net/2018/03/13/qt-quick-controls-2-automatically-set-the-width-of-menus.html @@ -45,5 +32,25 @@ Menu } return result + padding * 2; } + + function adjustWidth() + { + root.width = shouldBeVisible ? setWidth() : 0 + } + + function handleVisibility() + { + if(parent) + { + root.parent.visible = shouldBeVisible + root.parent.height = shouldBeVisible ? UM.Theme.getSize("menu").height : 0 + adjustWidth() + } + } + + onParentChanged: handleVisibility() + Component.onCompleted: handleVisibility() + onShouldBeVisibleChanged: handleVisibility() + onAboutToShow: adjustWidth() implicitWidth: setWidth() } \ No newline at end of file diff --git a/UM/Qt/qml/UM/MenuItem.qml b/UM/Qt/qml/UM/MenuItem.qml index 7f5ea0c1c..12c804b67 100644 --- a/UM/Qt/qml/UM/MenuItem.qml +++ b/UM/Qt/qml/UM/MenuItem.qml @@ -84,8 +84,7 @@ MenuItem { // Middle margin id: middleSpacer - width: visible ? UM.Theme.getSize("default_margin").width : 0 - visible: _shortcut.nativeText != "" || root.subMenu + width: (_shortcut.nativeText != "" || root.subMenu) ? UM.Theme.getSize("default_margin").width : 0 } UM.Label