当前位置: 代码迷 >> QT开发 >> QML 页递给互
  详细解决方案

QML 页递给互

热度:100   发布时间:2016-04-25 04:42:26.0
QML 页面交互
我想做一个键盘,键盘上有二者显示的内容
我的想法是通过一个控件的的鼠标信号来改变第一级Item的一个属性,在由这个属性来修改每个控件的显示内容。
CSS code
Item {    id: softkey    width: 800    height: 388    clip: false    property bool m_shift: false;    Rectangle {        id: rectangle1        x: 0        y: 0        width: 800        height: 388        Key {                id: key1                x: 10                y: 163                width: 84                height: 50                key_name1 : " "                key_name2 : " "                MouseArea {                   onReleased : softkey.m_shift = !softkey.m_shift;                }           }       }

C/C++ code
Item {    id: key    width: 100    height: 62    property string key_name1;    property string key_name2;    Rectangle {        id: rectangle1        Text {            id: text1;            text: key_name1        }    }    MouseArea {        id: mouse_area1        anchors.fill: parent    }    states: [        State {            name: "state2";when: solftkey.m_shift            PropertyChanges {                target: text1                text: key_name2            }        }    ]}

但我这样做根本不下,哪位大仙指导一下,已经2天了

------解决方案--------------------
// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
import QtQuick 1.1

Item {
id: key
width: 100
height: 62
property string key_name1;
property string key_name2;
state:"state1"
Rectangle {
id: rectangle1
width: 100
height: 62
color: "lightblue"
Text {
id: text1;
text: key_name2
}
}
states: [
State {
name: "state2";when: solftkey.m_shift
PropertyChanges {
target: text1
text: key_name2
}
},
//!!!!!!!!!!!!!!!!!!!!!!!!!!
State {
name: "state1";when: solftkey.m_shift
PropertyChanges {
target: text1
text: key_name1
}
}
//!!!!!!!!!!!!!!!!!!!!!!!!!!

]
}








// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
import QtQuick 1.1

Item {
id: softkey
width: 800
height: 388
clip: false
property bool m_shift: false;
Rectangle {
id: rectangle1
x: 0
y: 0
width: 800
height: 388
Key {
id: key1
x: 10
y: 163
width: 84
height: 50
key_name1 : "key_name1"//!!!!!!!!!!!!!!!!!!!!!!!!!!
key_name2 : "key_name2"//!!!!!!!!!!!!!!!!!!!!!!!!!!
MouseArea {
anchors.fill: parent//!!!!!!!!!!!!!!!!!!!!!!!!!!
onReleased :
{
key1.state = (key1.state==="state1"? "state2":"state1")//!!!!!!!!!!!!!!!!!!!!!!!!!!
softkey.m_shift = !softkey.m_shift;//!!!!!!!!!!!!!!!!!!!!!!!!!!
console.log(key1.state)
}

}
}
}
}


冒昧的修改了下楼主的代码(已用!!!!标出),不知道楼主要的是不是这种效果。
  相关解决方案