Skip to content

Commit

Permalink
Fix menu issues/warnings
Browse files Browse the repository at this point in the history
CURA-11102
  • Loading branch information
wawanbreton committed Nov 1, 2023
1 parent 72f42e7 commit bfca4d9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
33 changes: 20 additions & 13 deletions UM/Qt/qml/UM/Menu.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}
3 changes: 1 addition & 2 deletions UM/Qt/qml/UM/MenuItem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bfca4d9

Please sign in to comment.