2017-03-22 11 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

あなたは同時にアンカーとレイアウトを使用しないようにしてください。同じレベルでそれらを混在させると、レイアウトの誤動作や予期しない結果につながります(ただし、レイアウト内のアイテム内のアンカーを使用することはOKです)。

レイアウト内のアイテムを整列するには、添付プロパティ、Layout.alignment(例: )を使用できます。Layout.alignment:Qt.AlignHCenter | Qt.AlignVCenter このステートメントは、アイテムをレイアウトの中央に正確に配置します。

関連する問題