이 코드는 나를 위해 작동 :
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
변경 될 때마다 업데이트됩니다.
그렇다면 구성 요소 제공 업체가 이미 이와 같은 내용을 포함하고 있지 않은지 확인하십시오. 아마도 바퀴를 다시 발명하고있는 것입니다.
문제에 대해 좀 더 자세히 설명해 주시면 어떨까요? http://www.catb.org/esr/faqs/smart-questions.html#classic –
"사용하고 있습니다. 이 직사각형 버튼 대신 --- "버튼이 옵션이지만, 버튼은 qtquick 코어의 일부가 아닙니다. 어떤 외부 라이브러리를 사용합니까? 'qt-components'는 심비안/메가 또는 우분투 폰의 무언가입니까? 또한 라디오 버튼에 대한 표준 구성 요소가 있는지 확인하십시오. –