• 5592阅读
  • 2回复

[提问][已解决] 怎么动态应用Glow效果 [复制链接]

上一主题 下一主题
离线yurenjimi
 

只看楼主 倒序阅读 楼主  发表于: 2012-03-16
关键词: GlowQt5source
当点击Rectangle时,应用Glow 效果。
上码:

  1. import QtQuick 2.0
  2. import QtGraphicalEffects 1.0
  3. Rectangle {
  4.     width: 200; height: 200
  5.     color: "black"
  6.     Text {
  7.         id: text
  8.         anchors.centerIn: parent
  9.         text: "Hello Qt!"
  10.         font.pixelSize: 30
  11.         color: "white"
  12.     }
  13. /* 可以用,但是是静态的
  14.     Glow {
  15.         anchors.fill: text
  16.         source: text
  17.         color: "red"
  18.         radius: 10
  19.         samples: 20
  20.         visible: true
  21.         NumberAnimation on spread {
  22.             from: 0; to: 0.8; duration: 1000
  23.             loops: NumberAnimation.Infinite
  24.             easing.type: Easing.InOutQuad
  25.         }
  26.     }*/
  27.     Loader {
  28.         id: loader
  29.         focus: true
  30.     }
  31.     MouseArea {
  32.         anchors.fill: parent
  33.         onClicked: {
  34.             console.log("Clicked")
  35.             loader.sourceComponent = glowEffect
  36.         }
  37.     }
  38.     Component {
  39.         id: glowEffect
  40.         Glow {
  41.             anchors.fill: parent
  42.             source: parent
  43.             color: "red"
  44.             radius: 10
  45.             samples: 20
  46.             visible: true
  47.             NumberAnimation on spread {
  48.                 from: 0; to: 0.8; duration: 1000
  49.                 loops: NumberAnimation.Infinite
  50.                 easing.type: Easing.InOutQuad
  51.             }
  52.         }
  53.     }
  54. }

Glow效果肯定是生成了,因为
  1. Number of leaked textures: 2
  2. Number of leaked materials: 0
  3. Number of leaked nodes: 0
  4. Number of leaked items: 0

但是不清楚为什么看不到效果, 怀疑是source 的设置不对,但是应该怎么设置呢?




hello world!!
离线yurenjimi

只看该作者 1楼 发表于: 2012-03-19
Anyone ?
hello world!!
离线yurenjimi

只看该作者 2楼 发表于: 2012-03-19
问题出在两个方面,第一个是source, 第二个是anchors.fill。修改如下:
  1. //            anchors.fill: parent // 弃用
  2.             x: text.x; y: text.y   //必须指定
  3.             width: text.width; height: text.height // 必须指定
  4.             source: text




hello world!!
快速回复
限100 字节
 
上一个 下一个