2016-11-08 7 views
2

とテーブルビューのチェックボックス:センター私は次のように私はQMLで定義テーブルビュー、チェックボックスコントロールを使用していますQML

import QtQuick 2.2 
import QtQuick.Controls 1.4 
import QtQuick.Controls.Styles 1.4 

TableViewColumn { 
    title: "" 
    role: "check"  
    delegate: CheckBox { 
     anchors.fill: parent 
     checked: false 
     anchors { horizontalCenter: parent.horizontalCenter } 
    } 
} 

次のように私はテーブルビューでそれを使用することができます。

import QtQuick 2.3 
import QtQuick.Window 2.2 
import QtQuick.Layouts 1.1 

import QtQuick.Controls 1.4 
import QtQuick.Controls.Styles 1.4 

ControlView { 
    visible: true 
    width: parent.width; height: parent.height  
    anchors.centerIn: parent 

    TableView { 
     id: reviewTable 
     width: parent.width; height: parent.height 
     anchors.centerIn: parent 

     TableViewCheckBoxColumn { 
      title: "Upload" 
      width: 100 
      resizable: false 
     } 

     TableViewColumn { 
      resizable: true 
      role: "Dummy" 
      title: "Dummy" 
      width: 250 
     } 

     style: TableViewStyle { 
      headerDelegate: Rectangle { 
       height: textItem.implicitHeight 
       width: textItem.implicitWidth 

       Text { 
        id: textItem 
        anchors.fill: parent 
        verticalAlignment: Text.AlignVCenter 
        text: styleData.value 
        renderType: Text.NativeRendering 
        font.bold: true      
       } 
      } 
     }   

     model: ListModel { 
      ListElement { 
       Dummy: "value 1" 
      } 
      ListElement { 
       Dummy: "value 3" 
      } 
     } 
    } 
} 

アンカー(または使用可能なアライメントプロパティ)を設定したにもかかわらず、チェックボックスは左揃えのままです。どのように私はそれを列に水平に置くことができますか?

答えて

1

ラップデリゲートでCheckBox以下のように:

Item { 
    anchors.fill: parent 
    CheckBox { 
     anchors.centerIn: parent 
     checked: false 

    } 
} 

そして、ところで、同じアプリケーションでQtQuickバージョンを混在させないでください。

+0

残念ながら、これは機能しませんでした。私は同じ出力を得る。 Component not readyエラーで 'anchors.fill:parent'を追加できません。 – Luca

+0

おそらく、あなたはすべてのソースコードを提供していません。それは魅力のように私のために働く – folibis

+0

それは実際に働く。私は完全に誤解を受けています...もっと読むべきです。謝罪。 – Luca

関連する問題