2013-03-05 2 views
1

3 푸시 버튼이있는 창을 원하지만이 푸시 버튼은 라디오 버튼처럼 작동해야합니다! 2END 시간 다른 버튼을 클릭 내가 그것을 어떻게 해결할 수있을 때 나는이 사각형 대신 버튼을 사용하지만 그것이 proble을 가지고qml의 사용자 정의 라디오 버튼

Rectangle { 
    id: sideButton 
    color: sideButtonMouseArea.containsMouse ? '#DDDDDD' : '#F4F4F4' 
    property string text: 'Button' 
    MouseArea { 
     id: sideButtonMouseArea 
     anchors.fill: parent 
     hoverEnabled: true 
     onClicked: { 
      parent.color = '#4872E8' 
      sideButtonLabel.color = '#E2EBFC' 
     } 
    } 

    Text { 
     id: sideButtonLabel 
     text: sideButton.text 
     font.pixelSize: 20 
     font.family: 'Tahoma' 
     anchors.centerIn: sideButton 
     color: '#787878' 
    } 
} 

: 은 그래서 이것은 내 코드?

+0

문제에 대해 좀 더 자세히 설명해 주시면 어떨까요? http://www.catb.org/esr/faqs/smart-questions.html#classic –

+0

"사용하고 있습니다. 이 직사각형 버튼 대신 --- "버튼이 옵션이지만, 버튼은 qtquick 코어의 일부가 아닙니다. 어떤 외부 라이브러리를 사용합니까? 'qt-components'는 심비안/메가 또는 우분투 폰의 무언가입니까? 또한 라디오 버튼에 대한 표준 구성 요소가 있는지 확인하십시오. –

답변

3

이 코드는 나를 위해 작동 :

MyRadioGroup.qml

import QtQuick 1.0 

QtObject { 
    property Item selected : null 
} 

에게

import QtQuick 1.0 

Rectangle { 
    id: sideButton 
    property string text: 'Button' 
    property MyRadioGroup radioGroup 

    color: radioGroup.selected === sideButton ? '#E2EBFC' : 
      (sideButtonMouseArea.containsMouse ? '#DDDDDD' : '#F4F4F4') 
    MouseArea { 
     id: sideButtonMouseArea 
     anchors.fill: parent 
     hoverEnabled: true 
     onClicked: sideButton.radioGroup.selected = sideButton 
    } 

    Text { 
     id: sideButtonLabel 
     text: sideButton.text 
     font.pixelSize: 20 
     font.family: 'Tahoma' 
     anchors.centerIn: sideButton 
     color: radioGroup.selected === sideButton ? '#E2EBFC' : '#787878' 
    } 
} 

main.qml

MyRadioButton.qml을
import QtQuick 1.0 

Rectangle { 
    height: 600 
    width: 600 

    MyRadioGroup { 
     id: radioGroup1 
    } 

    Column { 
     anchors.fill: parent 

     MyRadioButton { 
      anchors { left: parent.left; right: parent.right } 
      text: "Button 1" 
      radioGroup: radioGroup1 
      height: 100 
     } 

     MyRadioButton { 
      anchors { left: parent.left; right: parent.right } 
      text: "Button 2" 
      radioGroup: radioGroup1 
      height: 100 
     } 

     MyRadioButton { 
      anchors { left: parent.left; right: parent.right } 
      text: "Button 3" 
      radioGroup: radioGroup1 
      height: 100 
     } 

     MyRadioButton { 
      anchors { left: parent.left; right: parent.right } 
      text: "Button 4" 
      radioGroup: radioGroup1 
      height: 100 
     } 
    } 
} 

설명 : 현재 선택된 항목을 보유 할 컨테이너 MyRadioGroup을 생성했습니다. 그런 다음 selected 속성을 color 속성 (내 MyRadioButton -s)으로 선언적으로 바인딩하므로 selected 변경 될 때마다 업데이트됩니다.


그렇다면 구성 요소 제공 업체가 이미 이와 같은 내용을 포함하고 있지 않은지 확인하십시오. 아마도 바퀴를 다시 발명하고있는 것입니다.

관련 문제