2017-03-22 4 views
0

요소를 가운데에 배치 할 수있는 방법 ColumnLayout? 내가 columnLayout도에 선택 상자를 중심하려는ColumnLayout에 요소를 가운데에 배치하는 방법

ApplicationWindow { 
    id: root 
    visible: true 
    width: 640 
    height: 640 
    title: qsTr("Your Booking") 
    GridLayout{ 
     anchors.fill: parent 
     columns: 2 
     flow: GridLayout.TopToBottom 
     Rectangle{ 
      id: appBar 
      Layout.columnSpan: 2 
      width: root.width 
      height: root.height/10 
      color: "red" 
     } 
     ColumnLayout{ 
      spacing:5 
      id: columnData 
      height: root.height - appBar.height 
      width: root.width/2 

      ComboBox{ 
       anchors.horizontalCenter: parent.horizontalCenter 
      } 
      ComboBox{ 

      } 
      ComboBox{ 
      } 
      ComboBox{ 
      } 
      ComboBox{ 
      } 
     } 
     ColumnLayout{ 

     } 

    } 
} 

:

여기 내 QML 코드입니다.

enter image description here

답변

1

당신은 같은 시간에 앵커와 레이아웃을 사용하지 않아야합니다. 동일한 레벨에서 이들을 혼합하면 레이아웃의 오작동이나 예상치 못한 결과가 발생할 수 있습니다 (단, 레이아웃의 항목 안의 앵커 사용은 괜찮습니다).

레이아웃에서 항목을 정렬하려면 Layout.alignment 속성 (예 : )을 사용하면됩니다. Layout.alignment : Qt.AlignHCenter | Qt.AlignVCenter 이 문장을 사용하면 항목이 레이아웃의 가운데에 정확히 위치하게됩니다.

관련 문제