[Development] QtQuick.Layouts and content margins

Alberto Mardegan mardy at users.sourceforge.net
Sun Feb 24 12:29:22 CET 2019


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.

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



More information about the Development mailing list