2017-04-22 14 views
1

슬라이더 componet에 스타일 데이터에 액세스 할 수 없습니다 :QML : 나는 슬라이더의 핸들 폭의 값이 필요하지만, 난 그냥 Qt는 문서에서 예제 코드를 복사 할 경우에도, 디버거가 여전히 말해

재산을 읽을 수 없습니다 ' handleWidth 'of null

내가 뭘 잘못 했니?

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

Slider { 
    anchors.centerIn: parent 

    style: SliderStyle { 
     groove: Rectangle { 
      implicitWidth: 200 
      implicitHeight: 8 
      color: "gray" 
      radius: 8 
     } 
     handle: Rectangle { 
      anchors.centerIn: parent 
      color: control.pressed ? "white" : "lightgray" 
      border.color: "gray" 
      border.width: 2 
      implicitWidth: 34 
      implicitHeight: 34 
      radius: 12 

      Text{ 
       text:"test" 
       anchors.right:parent.right 
       anchors.rightMargin: styleData.handleWidth * 0.3 
      } 
     } 
    } 
} 

UPDATE 아래와 같이

내 코드 : 나는 결국 해결 방법을 발견했다. 상태 및 속성 변경을 사용하면 슬라이더 수준의 '핸들'속성 아래에서 항목의 속성을 변경할 수 있습니다.

+0

나는 "styleData.handleWidth"을 인쇄 할 Component.onCompleted를 사용하는 경우, 내가 가지고 : 스타일 데이터가 – Anna

답변

1

not documented이므로 공개 속성이 아닙니다.

Here's the relevant source

:

handleLoader 선언에는 styleData 객체가 없다는 것을
Loader { 
    id: grooveLoader 
    property QtObject styleData: QtObject { 
     readonly property int handlePosition: handleLoader.x + handleLoader.width/2 
    } 
    x: padding.left 
    sourceComponent: groove 
    width: (horizontal ? parent.width : parent.height) - padding.left - padding.right 
    y: Math.round(padding.top + (Math.round(horizontal ? parent.height : parent.width - padding.top - padding.bottom) - grooveLoader.item.height)/2) 
} 
Loader { 
    id: tickMarkLoader 
    anchors.fill: parent 
    sourceComponent: control.tickmarksEnabled ? tickmarks : null 
    property QtObject styleData: QtObject { readonly property int handleWidth: control.__panel.handleWidth } 
} 
Loader { 
    id: handleLoader 
    sourceComponent: handle 
    anchors.verticalCenter: grooveLoader.verticalCenter 
    x: Math.round((control.__handlePos - control.minimumValue)/(control.maximumValue - control.minimumValue) * ((horizontal ? root.width : root.height) - item.width)) 
} 

알 수 있습니다.

대리자 handle 대리자는 슬라이더의 핸들 크기를 결정하므로 자유롭게 값을 지정할 수 있습니다. 예를 들어, 핸들의 Base style's implementation를 참조하십시오

property Component handle: Item{ 
    implicitWidth: implicitHeight 
    implicitHeight: TextSingleton.implicitHeight * 1.2 

    FastGlow { 
     source: handle 
     anchors.fill: parent 
     anchors.bottomMargin: -1 
     anchors.topMargin: 1 
     smooth: true 
     color: "#11000000" 
     spread: 0.8 
     transparentBorder: true 
     blur: 0.1 

    } 
    Rectangle { 
     id: handle 
     anchors.fill: parent 

     radius: width/2 
     gradient: Gradient { 
      GradientStop { color: control.pressed ? "#e0e0e0" : "#fff" ; position: 1 } 
      GradientStop { color: "#eee" ; position: 0 } 
     } 
     Rectangle { 
      anchors.fill: parent 
      anchors.margins: 1 
      radius: width/2 
      border.color: "#99ffffff" 
      color: control.activeFocus ? "#224f7fbf" : "transparent" 
     } 
     border.color: control.activeFocus ? "#47b" : "#777" 
    } 
} 
+0

가 답장을 보내 주셔서 감사 정의되지 않은, 이유를 I 핸들 버튼의 내용이 동적이기 때문에 정보가 필요합니다. 변경 사항에 맞게 다른 GUI 부품을 조정해야합니다. – Anna