懒得写那么多,好吧,太懒了,把解释都写在了代码的注释了,一看就明白的。很简单。布局
import QtQuick 2.3 import QtQuick.Window 2.2 import QtQuick.Controls 1.2 Window { visible: true Text { id: helloworld; //anchors.centerIn: parent;//要想实现控件的移动,就必须把这个布局给屏幕,不然移动是无效的 text: qsTr("helloworld"); font{ bold: false; pixelSize: 20; } Keys.onLeftPressed: x-=10; Keys.onRightPressed: x+=10; focus: true;//只有得到焦点的控件才可以响应鼠标事件 } MouseArea{ anchors.fill: parent;//鼠标响应区域填充为整个区域 acceptedButtons: Qt.LeftButton|Qt.RightButton; //响应单击事件 onClicked: { if(mouse.button==Qt.LeftButton) { helloworld.text="eeeeee"; } else { helloworld.text="wwww"; } } //响应双击事件 onDoubleClicked: { if(mouse.button==Qt.LeftButton){ helloworld.text="left double"; } else { helloworld.text="right double"; } } } }