मेरे पास एक माउस एरिया है कि मैं केंद्र से शुरू करना चाहता हूं और फिर ऊपर/नीचे/बाएं/दाएं कुंजी दबाए जाने के बाद एक पूर्ण स्थिति हो।साफ़ क्यूएमएल एंकर
import QtQuick 2.0
import QtQuick.Window 2.0
Window {
id: screen
width: 360
height: 360
visible: true
Rectangle {
anchors.fill: parent
states: [
State {
name: "moved"
AnchorChanges {
target: mouseArea
anchors.bottom: undefined
anchors.left: undefined
anchors.right: undefined
anchors.top: undefined
}
}
]
MouseArea {
id: mouseArea
anchors.centerIn: parent
width: 250
height: 250
focus: true
onClicked: console.log("clicked!")
onPositionChanged: console.log("position changed!")
function moveMouseArea(x, y) {
mouseArea.x += x;
mouseArea.y += y;
mouseArea.state = "moved";
mouseAreaPosText.text = 'Mouse area was moved... new pos: '
+ mouseArea.x + ', ' + mouseArea.y;
}
Keys.onPressed: {
if (event.key === Qt.Key_Up)
moveMouseArea(0, -1);
if (event.key === Qt.Key_Down)
moveMouseArea(0, 1);
if (event.key === Qt.Key_Left)
moveMouseArea(-1, 0);
if (event.key === Qt.Key_Right)
moveMouseArea(1, 0);
}
Rectangle {
anchors.fill: parent
border.width: 2
border.color: "black"
color: "transparent"
}
Text {
id: mouseAreaPosText
anchors.centerIn: parent
}
}
}
}
पहले मैं सिर्फ undefined
को mouseArea.anchors
स्थापित करने की कोशिश की पर लेकिन anchors
के बारे में एक त्रुटि मिली एक किया जा रहा है: मेरी समस्या मैं कैसे MouseArea पर लंगर स्पष्ट करने के लिए नहीं पता है कि इतना है कि मैं एक निरपेक्ष स्थिति निर्दिष्ट कर सकते हैं केवल पढ़ने के लिए संपत्ति। तब मैंने एंकर चेंज की खोज की, लेकिन मुझे एंकर को हटाने/साफ़ करने का कोई तरीका नहीं मिला; anchors.bottom
आदि undefined
पर काम नहीं करता है।
डॉक्स (http://qt-project.org/doc/qt-4.8/qml-anchor-layout.html) ने कहा, "यदि आप एंकर-आधारित पूर्ण स्थिति के आधार पर बदलना चाहते हैं, तो आप एंकर को साफ़ कर सकते हैं इसे 'अपरिभाषित' पर सेट करके मूल्य। – sergk