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] animating text color on keypress
QtWS25 Last Chance

[solved] animating text color on keypress

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 2 Posters 1.4k 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.
  • U Offline
    U Offline
    uroller
    wrote on last edited by
    #1

    I'm trying to do something simple that's not working out. I have text that turns from "white" to "yellow" when the user focus it. Now, I want it to flash green briefly when the user changes the value by key press. I thought it would just be:

    @
    Item
    {
    Text {
    id: value_text;
    color: "white";
    }

    ColorAnimation {
        id: key_press_animation;
        target: value_text;
        from: "green";
        to: "yellow";
    }
    
    states: [
        State {
            name: "FOCUS";
            when: ...
            PropertyChanges { target: value_text; color: "yellow"; }
        }
    ]
    
    Keys.onPressed: {
        key_press_animation.restart();
    }
    

    }
    @

    I am using states and I think that is messing something up. What am I missing?

    SOLVED:

    Looks like it's just a problem with ColorAnimation. Replace it with PropertyAnimation and it works straight away.

    @
    PropertyAnimation {
    property: "color"
    id: key_press_animation;
    target: value_text;
    from: "green";
    to: "yellow";
    }
    @

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Try something like this. When is the state change ? When condition is not defined.

      @ColorAnimation {
          id : anim ;
          target : value_txt;
          from : "white"
          to: "green";
          duration: 2000
          property : "color"
          onStopped: {
                 console.log("ANim done")
                 top.state = "focus"
          }
      }@
      

      Here top is the id of element where States are defined.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • U Offline
        U Offline
        uroller
        wrote on last edited by
        #3

        I have two states. FOCUS is when activeFocus is true. The second state is when activeFocus is true and the user is changing the value. While I'm in the second state I want to flash green.

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          when you are going from first state to second state, do you need to flash the green ? Is that correct ? In that case try using transitions along with states.

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          0
          • U Offline
            U Offline
            uroller
            wrote on last edited by
            #5

            No, I don't need a flash then.

            1 Reply Last reply
            0
            • U Offline
              U Offline
              uroller
              wrote on last edited by
              #6

              I am on Qt 4.7, so I don't have the onStopped callback.

              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