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. How to set padding or margin on GridLayout ...
Qt 6.11 is out! See what's new in the release blog

How to set padding or margin on GridLayout ...

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 2.9k Views
  • 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.
  • JehyeokJ Offline
    JehyeokJ Offline
    Jehyeok
    wrote on last edited by
    #1

    I redefined GridLayout for reusable reason.
    Grid has padding, but GridLayout doesn't.
    Do you have any idea to use padding or margin on it?

    Rectangle {
      width: 250
      height: childrenRect.height
    
      MyGridLayout{
      // padding or margin : 10
        MyGridLayout{
          orientation:1
          text { text: "input" }
          textfield { }
        }
        Button { text: "OK"
          
        }
      }
    
    }
    

    MyGridLayout.qml

    GridLayout{
    	property int orientation : 0 // 0: vertical, 1: horizontal
    	property double spacing : 10
    	property double margin : 0
    
    	columns : (orientation == 0) ? 1 : 0
    	rows : (orientation == 0) ? 0 : 1
    	columnSpacing : spacing
    	rowSpacing : spacing
    
    	width : parent.width
    	height : (visible) ? childrenRect.height : 0
    	//x : margin
    	//y : margin
    	//width : parent.width - (margin * 2)
    	//height : childrenRect.height + margin * 2
    	//Layout.preferredHeight: childrenRect.height + margin
    	Layout.alignment : Qt.AlignTop
    
    	flow : (orientation == 0) ? GridLayout.LeftToRight : GridLayout.TopToBottom
    }
    
    
    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