简体   繁体   中英

KDE widget - problem with icon size and the parent item

I would like to modify the KDE widget User Switcher to let the user decide the size of the icons to be shown in the fullRepresentation view. The user set a value in a combobox in the settings, and the view should automatically update.

To achieve this, I've added the code iconSize: getIconSize(combo_currentIndex) in each ListDelegate instance . Here, getIconSize is a simple javascript function that returns the specified value from units.iconSizes .

Then, I tried two approaches:

Approach 1 : In ListDelegate.qml I have created the property alias iconSize: icon.Layout.minimumWidth . It doesn't work , the widget load and shout out this error: ListDelegate.qml:41:30: Invalid alias target location: Layout .

Approach 2 : In ListDelegate.qml I have created the property int iconSize: units.iconSize.medium (I chose medium because that's the default option in the user settings). Then I changed the Layouts properties of the PlasmaCore.IconItem as follows:

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

At this point, the size of the icons changes accordingly to the user settings. But the ListDelegate item height remain fixed (as it were still using units.iconSize.medium ), therefore the icons overlaps when the user chooses an icon size greater than medium.

What can I do to solve this problem?

After reading the docs , I have fully understand how Layout works.

The solution of Approach 2 is quite simple. I also needed to set the correct values to the Layout properties minimumHeight , maximumHeight and preferredHeight of the parent element (which is the RowLayout row ):

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

The code should be self explanatory. In doing so, the parent RowLayout element is able to correctly change it's height to accomodate the icon.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM