Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. how to set text.visible=true that work in function is defined?

how to set text.visible=true that work in function is defined?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
8 Posts 2 Posters 2.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    stackprogramer
    wrote on 7 Jan 2016, 07:48 last edited by stackprogramer 1 Jul 2016, 07:56
    #1

    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???????

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Charby
      wrote on 7 Jan 2016, 09:20 last edited by
      #2

      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.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        stackprogramer
        wrote on 7 Jan 2016, 14:22 last edited by stackprogramer 1 Jul 2016, 14:23
        #3

        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??

        1 Reply Last reply
        0
        • S Offline
          S Offline
          stackprogramer
          wrote on 8 Jan 2016, 20:23 last edited by stackprogramer 1 Aug 2016, 20:25
          #4

          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!!!!!

          1 Reply Last reply
          0
          • S Offline
            S Offline
            stackprogramer
            wrote on 10 Jan 2016, 21:04 last edited by stackprogramer 1 Oct 2016, 21:04
            #5

            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.......

            1 Reply Last reply
            0
            • S Offline
              S Offline
              stackprogramer
              wrote on 23 Jan 2016, 06:31 last edited by stackprogramer
              #6

              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

              C 1 Reply Last reply 23 Jan 2016, 08:40
              0
              • S stackprogramer
                23 Jan 2016, 06:31

                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

                C Offline
                C Offline
                Charby
                wrote on 23 Jan 2016, 08:40 last edited by
                #7

                @stackprogramer Yes this sounds way much better. Actually, the Timer was the recommandation of my previous comment !

                1 Reply Last reply
                1
                • S Offline
                  S Offline
                  stackprogramer
                  wrote on 23 Jan 2016, 14:04 last edited by
                  #8

                  yes,after some days i did your advice.thanks for contribution

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved