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. GridLayout equal size Text and Rectange
Forum Updated to NodeBB v4.3 + New Features

GridLayout equal size Text and Rectange

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 468 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.
  • F Offline
    F Offline
    ferreus
    wrote on last edited by
    #1

    Why the following works:

    GridLayout {
            anchors.fill: parent
    
            columns: 2
            rows: 2
    
            Rectangle {
                Layout.column: 0
                Layout.columnSpan: 1
                Layout.row: 0
                Layout.rowSpan: 1
                Layout.fillHeight: true
                Layout.fillWidth: true
    
                color: "red"
            }
    
            Rectangle {
                Layout.column: 1
                Layout.columnSpan: 1
                Layout.row: 0
                Layout.rowSpan: 1
                Layout.fillHeight: true
                Layout.fillWidth: true
    
                color: "green"
            }
    
            Rectangle {
                Layout.column: 0
                Layout.columnSpan: 2
                Layout.row: 1
                Layout.rowSpan: 1
    
                Layout.fillHeight: true
                Layout.fillWidth: true
    
                color: "blue"
            }
        }
    

    But if i replace one of Rectangles with Text, the Text width occupies most of the screen, and not being equal width with the green Rectangle?

    GridLayout {
            anchors.fill: parent
    
            columns: 2
            rows: 2
    
            Text {
                text: "But Why?"
                Layout.column: 0
                Layout.columnSpan: 1
                Layout.row: 0
                Layout.rowSpan: 1
                Layout.fillHeight: true
                Layout.fillWidth: true
    
                color: "red"
            }
    
            Rectangle {
                Layout.column: 1
                Layout.columnSpan: 1
                Layout.row: 0
                Layout.rowSpan: 1
                Layout.fillHeight: true
                Layout.fillWidth: true
    
                color: "green"
            }
    
            Rectangle {
                Layout.column: 0
                Layout.columnSpan: 2
                Layout.row: 1
                Layout.rowSpan: 1
    
                Layout.fillHeight: true
                Layout.fillWidth: true
    
                color: "blue"
            }
        }
    
    1 Reply Last reply
    0
    • AxelViennaA Offline
      AxelViennaA Offline
      AxelVienna
      wrote on last edited by
      #2

      Usual resizing behavior of a grid layout….it gives a text label the space it needs to display its text, to the extent possible.
      I don’t know which behavior you want (fixed label size, cutting the text if necessary? Line wrap?).
      You may wanna check sizePolicy or share more details.

      C++ and Python walk into a bar. C++ reuses the first glass.

      F 1 Reply Last reply
      0
      • AxelViennaA AxelVienna

        Usual resizing behavior of a grid layout….it gives a text label the space it needs to display its text, to the extent possible.
        I don’t know which behavior you want (fixed label size, cutting the text if necessary? Line wrap?).
        You may wanna check sizePolicy or share more details.

        F Offline
        F Offline
        ferreus
        wrote on last edited by
        #3

        @AxelVienna
        I would want my grid columns equal size. The text is not big, there is no need to allocate 90% of grid space for text.
        Run this example, you will see.
        Anyway, fixed this by setting preferredWidth to 0 for text.
        But the inconsistency is annoying.

        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