Set the width of model loading drop-down to the max of all elements

Then set the elements to be equal to that width, so they fill the complete width of the drop-down.

Contributes to issue CURA-9143.
This commit is contained in:
Ghostkeeper 2022-05-09 11:54:28 +02:00
parent d79921c964
commit f1d75fe827
No known key found for this signature in database
GPG Key ID: 68F39EA88EEED5FF

View File

@ -106,26 +106,34 @@ Item
{ {
id: openProviderColumn id: openProviderColumn
//The column doesn't automatically listen to its children rect if the children change internally, so we need to explicitly update the size. // Automatically set the width to fit the widest MenuItem
onChildrenRectChanged: // Based on https://martin.rpdev.net/2018/03/13/qt-quick-controls-2-automatically-set-the-width-of-menus.html
function setWidth()
{ {
popup.implicitHeight = childrenRect.height var result = 0;
popup.implicitWidth = childrenRect.width var padding = 0;
} for (var i = 0; i < fileProviderRepeater.count; ++i) {
onPositioningComplete: var item = fileProviderRepeater.itemAt(i);
if (item.hasOwnProperty("implicitWidth"))
{ {
popup.implicitHeight = childrenRect.height var itemWidth = item.implicitWidth;
popup.implicitWidth = childrenRect.width result = Math.max(itemWidth, result);
padding = Math.max(item.padding, padding);
} }
}
return result + padding * 2;
}
width: setWidth()
Repeater Repeater
{ {
id: fileProviderRepeater
model: prepareMenu.fileProviderModel model: prepareMenu.fileProviderModel
delegate: Button delegate: Button
{ {
leftPadding: UM.Theme.getSize("default_margin").width leftPadding: UM.Theme.getSize("default_margin").width
rightPadding: UM.Theme.getSize("default_margin").width rightPadding: UM.Theme.getSize("default_margin").width
width: contentItem.width + leftPadding + rightPadding width: openProviderColumn.width
height: UM.Theme.getSize("action_button").height height: UM.Theme.getSize("action_button").height
hoverEnabled: true hoverEnabled: true