mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-24 07:03:56 -06:00
Resize columns when TableView is resized
They should retain their width proportionally. This also fixes a case where the width of the TableView was initialised as 0 but then changed for some anchors due to weird bindings. Because it now updates the tableView when the width is changed. Contributes to issue CURA-8686.
This commit is contained in:
parent
fa177f5192
commit
ec21b167d0
1 changed files with 11 additions and 5 deletions
|
@ -36,7 +36,7 @@ Item
|
|||
model: columnHeaders
|
||||
Rectangle
|
||||
{
|
||||
width: Math.round(tableBase.width / headerRepeater.count)
|
||||
width: Math.max(1, Math.round(tableBase.width / headerRepeater.count))
|
||||
height: UM.Theme.getSize("section").height
|
||||
|
||||
color: UM.Theme.getColor("secondary")
|
||||
|
@ -80,21 +80,27 @@ Item
|
|||
{
|
||||
if(drag.active)
|
||||
{
|
||||
parent.parent.width = Math.max(10, parent.parent.width + mouseX); //Don't go smaller than 10 pixels, to make sure you can still scale it back.
|
||||
let sum_widths = 0;
|
||||
let new_width = parent.parent.width + mouseX; //Don't go smaller than 10 pixels, to make sure you can still scale it back.
|
||||
let sum_widths = mouseX;
|
||||
for(let i = 0; i < headerBar.children.length; ++i)
|
||||
{
|
||||
sum_widths += headerBar.children[i].width;
|
||||
}
|
||||
if(sum_widths > tableBase.width)
|
||||
{
|
||||
parent.parent.width -= sum_widths - tableBase.width; //Limit the total width to not exceed the view.
|
||||
new_width -= sum_widths - tableBase.width; //Limit the total width to not exceed the view.
|
||||
}
|
||||
let width_fraction = new_width / tableBase.width; //Scale with the same fraction along with the total width, if the table is resized.
|
||||
parent.parent.width = Qt.binding(function() { return tableBase.width * width_fraction });
|
||||
}
|
||||
tableView.forceLayout();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onWidthChanged:
|
||||
{
|
||||
tableView.forceLayout(); //Rescale table cells underneath as well.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue