KDE 小部件 - 图标大小和父项的问题

KDE widget - problem with icon size and the parent item

我想修改 KDE 小部件 User Switcher to let the user decide the size of the icons to be shown in the fullRepresentation 视图。用户在设置的组合框中设置了一个值,视图应该会自动更新。

为此,我在每个 ListDelegate instance 中添加了代码 iconSize: getIconSize(combo_currentIndex)。这里,getIconSize 是一个简单的 javascript 函数,它 returns 来自 units.iconSizes.

的指定值

然后,我尝试了两种方法:

方法 1:在 ListDelegate.qml 中,我创建了 property alias iconSize: icon.Layout.minimumWidth它不工作,小部件加载并喊出这个错误:ListDelegate.qml:41:30: Invalid alias target location: Layout

方法 2:在 ListDelegate.qml 中,我创建了 property int iconSize: units.iconSize.medium(我选择中,因为这是用户设置中的默认选项)。然后我将 PlasmaCore.IconItemLayouts 属性更改如下:

Layout.minimumWidth: iconSize
Layout.maximumWidth: iconSize
Layout.minimumHeight: iconSize
Layout.maximumHeight: iconSize

此时,图标的大小会根据用户设置而变化。但是 ListDelegate 项目高度保持固定(因为它仍在使用 units.iconSize.medium),因此当用户选择大于中号的图标尺寸时图标重叠。

我该怎么做才能解决这个问题?

After reading the docs,我已经完全理解Layout的工作原理了。

方法 2 的解决方案非常简单。我还需要为父元素的布局属性 minimumHeightmaximumHeightpreferredHeight 设置正确的值(即 RowLayout ):

Layout.minimumHeight: units.iconSizes.tiny
Layout.maximumHeight: units.iconSizes.enormous
Layout.preferredHeight: iconSize

代码应该是不言自明的。这样做时,父 RowLayout 元素能够正确地更改它的高度以适应图标。