Internal margin / padding for Column/Row layout?
-
Hi,
I'm pretty familiar with positioning: anchors, its margins and width/height bindings with parent but I'm still confused with some things. I'm trying to avoidwidth: parent.width
binding because I read in some Qt doc that it has performance affect and better use anchors.I'm wondering why
RowLayout
andColumnLayout
don't havepadding
property. If I want to have some extra spacing around whole control (or layout) then I need to anchor it somewhere and then useanchor.margins
or in layout's items setLayout.margins
but in this case I have to set it for each row/column. For example simpleRow {}
positioner haspadding
property which set offser arround whole layout and this is exactly what I want, whyRowLayout
andColumnLayout
don't have it? Reason why I can't useRow{}
because I can't figure out how to set item width to maximum like inRowLayout
where I just setTextField { Layout.fillWidth: true }
Real example.
ApplicationWindow
andheader
ApplicationWindow { header: TextField { id: headerBar }
With above, TextField has some default width and I would like to have it filled with application width. I could use
width: parent.width
, I know, but as I mentioned earlier, I would like avoid it. And header will have multiple rows so I have to use some layout anyway.The general reason why I'm asking this question is that I don't like that whole
ApplicationWindow
doesn't have any margins. Everything is just positioned at x:0 and y:0 which looks weird. My goal is to set some margin for whole application. In Qt Widgetsets, layouts works different. I can set main layout for all widgets in main form and this layout has margins which affects whole main form borders -
use a Page{} inside your ApplicationWindow, then add header
-
-
Thanks. Indeed this helped.
ApplicationWindow { Page { id: mainPage anchors.fill: parent anchors.margins: 10 header: MyHeaderBar { } footer: MyFooter{ } ListView { anchors.fill: parent clip: true } }
Now with
anchors.margins: 10
I have a global padding arround my whole application including footer, header and content items. Perfect