[Development] QtQuick.Layouts and content margins

Alberto Mardegan mardy at users.sourceforge.net
Mon Feb 25 21:35:29 CET 2019


On 25/02/19 15:57, Mitch Curtis wrote:
> My only issue with it is that I don't know if it will see much use
> outside of your use case. Usually if all items in a layout have the
> same margins, you would just apply those margins to the layout
> managing them instead. While I appreciate that that won't work in
> your case (because the Layout might not be within another, so the
> attached margin properties won't have any effect, and anchor margins
> are not included in its implicit size), I do wonder if there are
> other approaches you could take. What other options have you
> considered?

My immediate issue can be fixed by wrapping the layout into an Item that
aliases its properties and computed the proper implicit size:

==============
import QtQuick.Layouts 1.2
import it.mardy.Desktop.private 1.0

Item {
    default property alias data: layout.data
    implicitWidth: layout.implicitWidth + layout.anchors.leftMargin +...
    ...

    ColumnLayout {
        id: layout
        anchors {
            leftMargin: Style.layoutLeftMargin
            topMargin: Style.layoutTopMargin
            rightMargin: Style.layoutRightMargin
            bottomMargin: Style.layoutBottomMargin
        }
        spacing: Style.layoutVerticalSpacing
    }
}
==============

> What about just making the API that provides the style's
> margins available to the user so they can do it themselves?

That might happen as well, but the goal is not to require the user to
know about this class.

> Also, it would be good if you could provide some examples of other
> (more common) use cases that would benefit from this.

Well, having all items inside a layout share the same margins is quite
common. People currently do it with anchors and playing with the
(implicit) size of the parent, but it's not optimal.

The advantage of doing this in the layout items themselves is that there
the problem is reduced to some trivial arithmetic, without the need to
play with parent items.

Ciao,
  Alberto

-- 
http://www.mardy.it - Geek in un lingua international



More information about the Development mailing list