how to set text.visible=true that work in function is defined?
-
this is my source, when i want to when i clicked pressme,the text type mytext
is showed.(the former is hiden).then it wait 1000 ms the main.qml start.import QtQuick 2.2 import QtQuick.Window 2.1 import QtQuick.Controls 1.2 import QtQml 2.2 import QtQuick.Dialogs 1.2 import QtQuick.Controls.Styles 1.2 Window{id:page1 function delay(duration) { // In milliseconds var timeStart = new Date().getTime(); mytext.visible=true while (new Date().getTime() - timeStart < duration) { pageLoader2.source = "main.qml" } // Duration has passed } Loader { id: pageLoader2 } Text {id:mytext Component.onCompleted :{visible:false;} color:"red" style: Text.Outline; styleColor: "yellow" font.family: gamefont2.name font.pointSize:25; text: "<b>Score+10</b>" visible:false; MouseArea { anchors.fill: parent onClicked: { } } } Text {id:pressme color:"red" style: Text.Outline; styleColor: "yellow" font.family: gamefont2.name font.pointSize:25; text: "<b>pressme</b>" visible:true; MouseArea { anchors.fill: parent onClicked: {delay(1000); } } } }
my problem is the mytext when is show when it qml exit from delay function.
and the mytext has a time 1000 ms that we consider it for showing mytext,it don't show!!!!!!!!!
the text.visible=true don't work!!!!!!!11
how can i fixed it??????? -
It would help if you give a working source code (the window is not visible, gamefont2 is not defined).
The problem is with your delay function which contains a blocking loop - you really should avoid this and prefer a Timer element for instance...
Anyhow, with the current design, f you want your text to show up, you can set the its visibility in the "pressme" mousearea onClick handler before calling your delay function. -
It would help if you give a working source code (the window is not visible, gamefont2 is not defined).
this is some source code not all.
The problem is with your delay function which contains a blocking loop - you really should avoid this and prefer a Timer element for instance...
i want to use text.visible in function delay only ,this is my way for special reason.
can you about blocking loop more?? -
i moved the mytext.visible=true; to MouseArea,now my source is here
import QtQuick 2.2 import QtQuick.Window 2.1 import QtQuick.Controls 1.2 import QtQml 2.2 import QtQuick.Dialogs 1.2 import QtQuick.Controls.Styles 1.2 Window{id:page1 function delay(duration) { // In milliseconds var timeStart = new Date().getTime(); while (new Date().getTime() - timeStart < duration) { pageLoader2.source = "main.qml" } // Duration has passed } Loader { id: pageLoader2 } Text {id:mytext Component.onCompleted :{visible:false;} color:"red" style: Text.Outline; styleColor: "yellow" font.family: gamefont2.name font.pointSize:25; text: "<b>Score+10</b>" visible:false; MouseArea { anchors.fill: parent onClicked: { } } } Text {id:pressme color:"red" style: Text.Outline; styleColor: "yellow" font.family: gamefont2.name font.pointSize:25; text: "<b>pressme</b>" visible:true; MouseArea { anchors.fill: parent onDoublClicked: { mytext.visible=true; delay(1000); } } } }
but the mytext is n't showed.when i toggle comment function delay,it works!!!!!!!
how we can use functions in mousearea!!!!! -
my problem is not solved yet,i concluded i can not i can't use Timer type in javascript function,so i use the method getTime(),mytext is not show now.
this is strange in qml....... -
instead using this delay function in top code:
function delay(duration) { // In milliseconds var timeStart = new Date().getTime(); mytext.visible=true while (new Date().getTime() - timeStart < duration) { pageLoader2.source = "main.qml" }
i uses Timer type for create delay. in onTriggered i call other function in js and my problem is solved.thanks for attention and contribution
-
instead using this delay function in top code:
function delay(duration) { // In milliseconds var timeStart = new Date().getTime(); mytext.visible=true while (new Date().getTime() - timeStart < duration) { pageLoader2.source = "main.qml" }
i uses Timer type for create delay. in onTriggered i call other function in js and my problem is solved.thanks for attention and contribution
@stackprogramer Yes this sounds way much better. Actually, the Timer was the recommandation of my previous comment !
-
yes,after some days i did your advice.thanks for contribution