2017-11-08 4 views
0

왼쪽에서 오른쪽 RowLayoutRectangle을 정렬하고 싶습니다. 아래의 코드 예제에서 두 Rectangle은 추가 공간을 공유합니다. RowLayout 레벨과 Rectangle 레벨에서 Layout.alignment: Qt.AlignLeft을 사용했지만 두 가지 방법 중 어느 것도보기를 전혀 변경하지 않았습니다. 이미지를 검은 색 테두리는 다음의RowLayout에서 항목 정렬 방법

Item { 
    RowLayout { 
     anchors.fill: parent 
     spacing: 2 


     Rectangle { 
      width: 100 
      Layout.fillHeight: true 
      Layout.alignment: Qt.AlignLeft 

      Text { 
       text: "Hello world" 
      } 
     } 

     Rectangle { 
      width: 100 
      Layout.fillHeight: true 
      Layout.alignment: Qt.AlignLeft 

      Text { 
       text: "Hello world" 
      } 
     } 
    } 
} 

RowLayout과 빨간색 테두리가 Rectangle의 나타냅니다. 예상

는 실제

Acual layout

Layout.alignment에 대한

Expected layout

+0

'RowLayout' 대신'Row'를 사용하면 더 행복해 질 것입니다. 왜냐하면'Row'의 정상적인 동작이기 때문입니다. – derM

+0

어린이 Items에 정적 너비가있는 경우 가로형 RowLayout을 사용하는 것은 나에게별로 의미가 없습니다. 대신 행을 사용하고 행의 높이에 어린이의 높이를 묶습니다. –

답변

2

문서 상태 :

이 속성은 내 항목의 정렬을 지정할 수 있습니다 세포 ()가 차지합니다.

RowLayout { 
    anchors.fill: parent 
    spacing: 2 


    Rectangle { 
     width: 100 
     Layout.fillHeight: true 
     Layout.alignment: Qt.AlignLeft 
     color: 'red' 

     Text { 
      text: "Hello world" 
     } 
    } 

    Rectangle { 
     width: 100 
     Layout.fillHeight: true 
     Layout.alignment: Qt.AlignLeft 
     color: 'green' 

     Text { 
      text: "Hello world" 
     } 
    } 

    Item { 
     Layout.fillWidth: true 
    } 
} 

을하지만 다른 방법이 사용 :

당신은 단순히 같은 말에 필러 항목을 추가 할 수 있습니다

Row { 
    anchors.fill: parent 
    spacing: 2 


    Rectangle { 
     width: 100 
     anchors { 
      top: parent.top 
      bottom: parent.bottom 
     } 

     color: 'red' 

     Text { 
      text: "Hello world" 
     } 
    } 

    Rectangle { 
     width: 100 
     anchors { 
      top: parent.top 
      bottom: parent.bottom 
     } 
     color: 'green' 

     Text { 
      text: "Hello world" 
     } 
    } 
} 
0

당신은 다음과 같은 부정적인로 간격 값을 변경할 수 있습니다 :

RowLayout { 
    anchors.fill: parent 
    spacing: -parent.width*0.6 
    Rectangle { 
     width: 100 
     Layout.fillHeight: true 
     Layout.alignment: Qt.AlignLeft 
     border.width:1 
     border.color:"red" 
     Text { 
      text: "Hello world" 
     } 
    } 
    Rectangle { 
     width: 100 
     Layout.fillHeight: true 
     Layout.alignment: Qt.AlignLeft 
     border.width:1 
     border.color:"red" 
     Text { 
      text: "Hello world" 
     } 
    } 

}