自学QT之QML实现响应鼠标和键盘事件
2015-11-22 19:45
1581 查看
懒得写那么多,好吧,太懒了,把解释都写在了代码的注释了,一看就明白的。很简单。
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"; } } } }
相关文章推荐
- 自学QT之libpng warning: iCCP: known incorrect sRGB profile
- qt 窗口置顶/真透明/背景模糊/非矩形/跳过任务栏分页器/无边框/无焦点点击/焦点穿透
- QT5与之前版本间问题整理
- QTime中currentTime()的使用方法
- Qt中利用定时器QTimer准实时显示当前日期和时间
- Qt :非window子窗体的透明度设置
- 解析Qt的信号-槽机制是如何工作的 - How Qt Signals and Slots Work
- Qt的socket通信
- QT:数据库总结(三)之SQL模型类-QSqlTableModel模型
- qt for ios
- qt的俄罗斯方块游戏移植到OK6410的修改
- Qt 动态对话框
- Qt 改变形状的对话框
- QT上使用OpenCV
- 关于 QListWidget IconMode的使用
- QtNetwork: No such file or directory 问题的解决办法
- QT调用COM组件
- qt5.5实现 记事本程序
- windows编译qtav
- PyQt4(简单计算器)