我試圖為一張圖片設定一個定時器,但是該圖片需要在5秒內可見,然后逐漸消失,除非在點擊時再次觸發它。 以下是我的代碼:
視頻{
id:video
//width:500
//height:300
//anchors.left:parent
自動加載: true
自動播放: true
//hasVideo: true
//source: "http://qthttp.apple.com.edgesuite.net/1010qwoeiuryfg/0640_vod.m3u8"
width:isFullScreen?1080:500
高度:isFullScreen?1060:300
圖片{
id:img1
width:parent.width/5
height:parent.height/5
anchors.centerIn: parent
來源:'qrc:play-circle-outline.svg'
屬性 int duration:5000
MouseArea{
anchors.fill:parent
onClicked:{
if(video.playbackState===1){
video.pause()
img1.source='qrc:play-circle-outline.svg' 。
}else if(video.playbackState===2){
video.play()
img1.source='qrc:pause-outline.svg')
}
}
}
}
圖片{
id:img2
width:parent.width/5
高度:parent.height/5
anchors.bottom:video.bottom
anchors.right:video.right
source:isFullScreen? 'qrc:enter-outline.svg':'qrc:exit-outline.svg')
計時器 {
interval: 5000
onTriggered: img2.visible = true
運行: false
}
MouseArea{
anchors.fill:parent
/* onClicked:{
如果(isFullScreen){
video.height=300
video.width=500
img2.source='qrc:exit-outline.svg' 。
}else{
video.height=1060
視頻.寬度=1080/2
img2='qrc:enter-outline.svg' 。
}
}*/
onClicked:isFullScreen=!isFullScreen
}
}
我在img2下設定了一個定時器,但在播放視頻的整個程序中,影像仍然可見。我最擔心的是影像在點擊時再次被觸發的部分。如果有任何想法,我們將不勝感激。
編輯。
我設法用下面的PropertyAnimation在5秒后隱藏了影像img2:
PropertyAnimation {
running: true
target: rect
屬性: 'visible
to: false
持續時間。5000 // 5000毫秒后轉為假
}
我只需要讓圖片在點擊后5秒內再次可見。這在QML中可以實作嗎?
uj5u.com熱心網友回復:
可見性只是一個布林值,你不能以這種方式淡化QML專案。你必須要設定不透明度。我使用一個矩形而不是一個影像,只是為了讓事情變得簡單。在這個例子中,淡入和淡出都會發生。如果你想讓影像立即出現,那么需要做一點調整。
import QtQuick 2.12
輸入QtQuick.Controls 2.12
矩形
{
id: bg
anchors.fill: parent
顏色:"紅色"
計時器 {
id: tmr
間隔時間。5000
}
按鈕 {
z: img.z 1
anchors.centerIn: parent
text: tmr.running ? "運行中" : "啟動定時器"
onClicked: {
tmr.stop()
tmr.start()
}
}
矩形 {
id: img
寬度: 200
高度: 200
anchors.centerIn: parent
opacity: tmr.running ? 1.0 : 0.0
關于不透明度的行為 { PropertyAnimation { duration: 1000 } }
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/326118.html
標籤:
