Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Internal margin / padding for Column/Row layout?
Forum Updated to NodeBB v4.3 + New Features

Internal margin / padding for Column/Row layout?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 1.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kobid
    wrote on last edited by
    #1

    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 avoid width: parent.width binding because I read in some Qt doc that it has performance affect and better use anchors.

    I'm wondering why RowLayout and ColumnLayout don't have padding property. If I want to have some extra spacing around whole control (or layout) then I need to anchor it somewhere and then use anchor.margins or in layout's items set Layout.margins but in this case I have to set it for each row/column. For example simple Row {} positioner has padding property which set offser arround whole layout and this is exactly what I want, why RowLayout and ColumnLayout don't have it? Reason why I can't use Row{} because I can't figure out how to set item width to maximum like in RowLayout where I just set TextField { Layout.fillWidth: true }

    Real example. ApplicationWindow and header

    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

    1 Reply Last reply
    0
    • ekkescornerE Offline
      ekkescornerE Offline
      ekkescorner
      Qt Champions 2016
      wrote on last edited by
      #2

      use a Page{} inside your ApplicationWindow, then add header

      ekke ... Qt Champion 2016 | 2024 ... mobile business apps
      5.15 --> 6.9 https://t1p.de/ekkeChecklist
      QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

      1 Reply Last reply
      0
      • K Kobid has marked this topic as solved on
      • K Offline
        K Offline
        Kobid
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved