鱼C论坛

 找回密码
 立即注册
查看: 2008|回复: 0

[技术原创] 信号和槽--QT动画制作(十三)

[复制链接]
发表于 2017-3-4 13:51:12 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
效果:
sd.png
能学到这里的鱼油已经很厉害了,学编程时枯燥的,但是枯燥过后迎来的是喜悦
知识点1:学会使用信号与槽的两种方法
知识点2:学会使用按钮控件
知识点3:文本输入框
还是先新建个QT项目,再建个Rect.qml文件,代码如下:
  1. import QtQuick 2.0
  2. import QtQuick.Controls 1.3//这里包含按钮等各种控件
  3. Rectangle {
  4.     id:rect
  5.     width:400
  6.     height:400
  7.     color:"green"
  8.     Row{

  9.     Button{
  10.         id:btn
  11.         text:"点我"
  12.     }
  13.     Button{

  14.         id:btn1
  15.         text:"背景变为红色"
  16.     }
  17.     }
  18. Rectangle{
  19.     anchors.centerIn: parent
  20.     width:100
  21.     height: 20
  22. TextInput{
  23.     focus:true//光标自动进入文本框
  24.     id:input
  25.     width:100
  26.     height: 30
  27. }
  28. }
  29.     function a(){//js脚本的函数
  30.         btn.text=input.text
  31.     }
  32.     function b(){
  33.         rect.color="red"
  34.     }
  35.     Component.onCompleted: {
  36.         btn.clicked.connect(a)//点我按钮点击后触发a()函数
  37.     }
  38.     Connections{
  39.         target:btn1//设定信号来自于哪
  40.         onClicked:b()
  41.     }
  42. }
复制代码

main.qml文件:
  1. import QtQuick 2.5
  2. import QtQuick.Window 2.2

  3. Window {
  4.     visible: true
  5.     width: 640
  6.     height: 480
  7.     title: qsTr("Hello World")

  8.     MainForm {
  9.         anchors.fill: parent

  10.     }
  11. }
复制代码

MainForm.ui.qml文件:
  1. import QtQuick 2.5
  2. Rect{}
复制代码

preview: 明天我们将介绍控件中滑动条的使用,和另外一项图片渲染技巧

本帖被以下淘专辑推荐:

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-27 17:07

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表