2015-01-19 1 views
3

보기는 속성을 대리인에게 연결합니다. ListView를 들어, 대리인이 ListView.view.widthListView.isCurrentItem 속성에 액세스 할 수 있습니다 : 대리인이들이 generic을 상실 같은일반 QML 위임자 (일반이 아닌) 첨부 된 속성보기?

Rectangle { 
    width: ListView.view.width 
    height: 40 

    color: ListView.isCurrentItem ? "gray" : "lightGray" 

    Text { 
    anchors.centerIn: parent  
    text: index 
    } 
} 

을 해당 유형의 이름으로보기를 참조함으로써 보인다.

동일한 대리자를 GridView에서 사용하려면 어떻게해야합니까?

답변

2

대리인에게 구성 요소를 만들고 구체화 중에 property isCurrentItem으로 설정해야합니다. 즉, 새 qml 파일을 작성하고 이름을 지정하십시오.

ListView { 
    model: 10 
    width: 40 
    height: 200 
    delegate: Delegate { 
     isCurrentItem: ListView.isCurrentItem 
    } 
} 

유사의 GridView에서 : 당신이 좋아하는의 ListView에서 사용할 수있는 것보다

import QtQuick 2.4 

Rectangle { 
    property bool isCurrentItem: false 
    width: parent.width 
    height: 20 
    color: isCurrentItem ? "gray" : "lightGray" 
    Text { 
     anchors.centerIn: parent 
     text: index 
    } 
} 

"Delegate.qml"와 property bool isCurrentItem를 추가

GridView { 
    model: 10 
    width: 40 
    height: 200 
    delegate: Delegate { 
     isCurrentItem: ListView.isCurrentItem 
    } 
} 

당신은 그것을 같은 방식으로 할 수 대의원에게 ListView/GridViewwidth을 제공하지만이 경우 parent.width도 작동합니다. 네가 원하는대로.

관련 문제