Fit Grid elements in Item

David Edmundson david at davidedmundson.co.uk
Mon Sep 24 13:14:39 UTC 2012


On Mon, Sep 24, 2012 at 1:16 PM, Sebastian Kügler <sebas at kde.org> wrote:
> On Monday, September 24, 2012 11:45:22 David Edmundson wrote:
>> Although you've told the grid to anchor on the right hand side, you've
>> also (implicitly) told it it needs to be 4 buttons wide, and each
>> button is hardcoded to be at least 12 characters wide.
>> (plasmacomponents/qml/Button.qml:95). At which point even though the
>> grid is anchored to the parent, it' content is bigger so it shows it
>> all anyway.
>>
>> The way you can make it fit is to "fix" the button to not be really
>> massive, by adding a "width: grid.width/4.0 - grid.spacing"
>
> width: (grid.width / grid.columns) - grid.spacing
>
> even :)
Iterative development :P
>
>> Though you're in slightly dangerous territory here, as the plasmoid
>> should fit the size of the content, not shrinking the content to fit.
>> The last thing we want is for a plasmoid that can be resized to look
>> like this: http://wstaw.org/m/2012/09/24/plasma-desktopZ30680.png
>
> Setting a minimum size and using a popupapplet would be the way here. The
> applet then collapses if it doesn't have enough space.
>
>> It may be better to change Button.
>
> Not necessary, in Button.qml only implicitWidth is set, that's a fallback if
> the button doesn't have a size assigned explicitely (which is the case here).
>
> So, as David suggests, just setting the width of the button should work.

To clarify, by change I meant to consider adding a
minimumWidth/minimumHeight property, not removing the current
implicitWidth

It's impossible for a user of the component to do this accurately
because it needs both the label size, and the size of the surface
margins which are both internal.

I didn't want to say that explicitly because I'm far from the biggest
QML expert here, and there may well be a better way to accomplish the
same goal.

Dave


More information about the Plasma-devel mailing list