[Development] QtQuick.Layouts and content margins

Mitch Curtis mitch.curtis at qt.io
Mon Feb 25 09:23:33 CET 2019



> -----Original Message-----
> From: Development <development-bounces at qt-project.org> On Behalf Of
> Alberto Mardegan
> Sent: Sunday, 24 February 2019 12:29 PM
> To: development at qt-project.org
> Subject: [Development] QtQuick.Layouts and content margins
> 
> Hi there!
>   I'm working on a desktop style for QtQuick.Controls 2 [1], and I'm currently
> investigating the issue of layouts. My current approach is to define my own
> ColumnLayout element like this:
> 
> ==============
> import QtQuick.Layouts 1.2
> import it.mardy.Desktop.private 1.0
> 
> ColumnLayout {
>     anchors {
>         leftMargin: Style.layoutLeftMargin
>         topMargin: Style.layoutTopMargin
>         rightMargin: Style.layoutRightMargin
>         bottomMargin: Style.layoutBottomMargin
>     }
>     spacing: Style.layoutVerticalSpacing } ==============
> 
> where the Style element is a singleton which retrieves the default layout
> margins encoded in the QStyle.
> 
> Now, there's are a couple of problems with this solution: if the user of my
> layout does not set the "anchors.fill" property, but instead positions the
> layout using "x", "y", "width" or "heigh" properties, the margins will be
> ignored.
> The other (bigger) problem is that the implicit size of my layout is
> wrong: it should include the margins!
> 
> My proposal is to add a set of "margins" properties to QtQuick.Layout's
> items, which would set the default content margins for all child items that
> don't explicitly set their own via the attached Layout properties.
> These margins would also be taken into account when computing the implicit
> size of the layout.

So would it look something like this?

    // implicit size is 118 x 64
    ColumnLayout {
        defaultLeftMargin: 12
        defaultRightMargin: 12
        defaultBottomMargin: 12
        defaultTopMargin: 12

        // implicit size is 100 x 40
        Button {
            Layout.leftMargin: 6 // override default
        }
    }

> If this looks like a good idea, I can try and propose a patch.
> 
> Ciao,
>   Alberto
> 
> [1]: https://gitlab.com/mardy/qqc2-desktop
> 
> --
> http://www.mardy.it - Geek in un lingua international
> _______________________________________________
> Development mailing list
> Development at qt-project.org
> https://lists.qt-project.org/listinfo/development


More information about the Development mailing list