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. [Solved] qml MouseArea for button
Forum Updated to NodeBB v4.3 + New Features

[Solved] qml MouseArea for button

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 3 Posters 3.2k Views 1 Watching
  • 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.
  • G Offline
    G Offline
    goli
    wrote on last edited by
    #1

    Does anyone know how to create a button that is linked to Text (number) and above its value as long as the button pressed?

    i tried this:

    @
    Button
    {
    width:100
    height:100
    text: "up"
    onPressed:
    {
    ++myText.text;
    }
    }
    Text
    {
    id:myText
    text:1
    }
    @

    but this increases the value only once....

    [EDIT: code formatting, please wrap in @-tags, Volker]

    1 Reply Last reply
    0
    • N Offline
      N Offline
      njeisecke
      wrote on last edited by
      #2

      http://doc.qt.nokia.com/4.7-snapshot/qml-timer.html

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goli
        wrote on last edited by
        #3

        tnx :) . fixed

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          quocvu88_dn
          wrote on last edited by
          #4

          hi. I'm newbie

          I've just do what you tell (use QLM timer)

          But can you help me? I want to stop increasing the value of the text when i realease the button ?

          here is my code:

          @

          Rectangle
          {id: screen
          width: 360
          height: 360

          Text 
          

          { id: chu
          x: 155
          y: 142
          text: "1"
          font.pointSize: 40
          }

          Rectangle 
          

          {id: button

          x: 229
          
          y: 222
          
          
              width: 100
              height: 100
              color: "#be3f3f"
              radius: 20
              border.width: 3
              border.color: "#111010"
          
          
          
          
              states: 
          

          [

                  State 
          

          {

                      name: "State1"
          
          
                      when: MouseArea.pressed
          
                      PropertyChanges 
          

          {
          target: button
          color: "#6dbe3e"

                      }
          
                  }
          
              ]
          
          
              Text
          

          {

                  id: name
                  x: 24
                  y: 41
                  text: "up"
                  anchors.rightMargin: -23
                  anchors.bottomMargin: -41
                  anchors.leftMargin: 24
                  anchors.topMargin: 41
                  wrapMode: Text.WordWrap
                  anchors.fill: parent
                  font.pointSize: 11
          
              }
          
          
          
          
          
          MouseArea 
          

          {
          id: chuot
          anchors.fill: parent

              onClicked:
          

          {
          ++chu.text;
          time.start()
          }

          }
          

          }
          Item {
          Timer
          {id: time

                  interval: 100; running: false; repeat: true
                  onTriggered: chu.text++
          
          
              }
          

          }

          }@

          1 Reply Last reply
          0
          • N Offline
            N Offline
            njeisecke
            wrote on last edited by
            #5

            start the timer using the onPressed signal handler, stop it in onReleased

            1 Reply Last reply
            0
            • Q Offline
              Q Offline
              quocvu88_dn
              wrote on last edited by
              #6

              @njeisecke : i've tried start the timer using the onclicked signal handler, stop it in onReleased
              and your lesson is so good.

              thank you very much njeisecke. I've tried it all day. Thank you.

              I'm from Vietnam and want to learn about Qt to write some ap for my Nokia 5800 phone. Nice to meet you all. Sorry for my bad English. ^_^

              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