Fit Grid elements in Item

David Edmundson david at davidedmundson.co.uk
Mon Sep 24 10:45:22 UTC 2012


On Mon, Sep 24, 2012 at 4:05 AM, Luiz Romário Santana Rios
<luizromario at gmail.com> wrote:
> Hello.
>
> I'm trying to port the Calculator plasmoid to QML, but I'm stuck
> trying to make the buttons fit their parent item. I'm doing this:
>
> Item {
>     anchors {
>         top: resultArea.bottom
>         bottom: parent.bottom
>         left: parent.left
>         right: parent.right
>     }
>
>     Grid {
>         columns: 4
>         spacing: 2
>
>         anchors.fill: parent
>
>         Repeater {
>             model: ["C", "÷", "×", "AC",
>                     "7", "8", "9", "-",
>                     "4", "5", "6", "+"]
>
>             PlasmaComponents.Button {
>                 id: buttonC
>                 text: modelData
>             }
>         }
>     }
> }
>
> But I get this:
>
> http://i47.tinypic.com/1z33z3o.png
>
> Trying to anchor the buttons doesn't work either.
>
> What should I do?
>
It's important to explain why it acts the way it does first.

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"

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

It may be better to change Button.

Dave


> --
> Luiz Romário Santana Rios
> _______________________________________________
> Plasma-devel mailing list
> Plasma-devel at kde.org
> https://mail.kde.org/mailman/listinfo/plasma-devel


More information about the Plasma-devel mailing list