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 deal with the hover and press state of custom button?
Forum Updated to NodeBB v4.3 + New Features

How to deal with the hover and press state of custom button?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 263 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.
  • K Offline
    K Offline
    Kamichanw
    wrote on last edited by
    #1

    I'm writing a custom button, the code is shown below

    Rectangle {
        id: control
        color: "white"
        states: [
            State {
                name: "hover"
                when: ma.containsMouse
                PropertyChanges {
                    control.color: "blue"
                }
             },
             State {
                 name: "press"
                 when: ma.containsPress
                 PropertyChanges {
                     control.color: "red"
                 }
             }]
        transitions: [
            Transition {
                // from: <default state>
                to: "hover
                ColorAnimation{ /* some special settings */ }
            },
            Transition {
                from: "hover"
                to: "press"
                ColorAnimation{ /*other special settings */ } 
            }, // other Transitions
            ]
        MouseArea {
            id: ma
            hoverEnabled: true
        }
    }
    

    As you can see here, I want to customize the state trainsition among default, hover and press. However, I have no clue to deal with these states. You might advise me to create a new state called default. However, the color of control might be changed by user, that is, I cannot do like

    State {
        name: "default"
        PropertyChanges {
             control.color: constrol.color // ????
        }
    }
    

    Anyone can help?

    B 1 Reply Last reply
    0
    • K Kamichanw

      I'm writing a custom button, the code is shown below

      Rectangle {
          id: control
          color: "white"
          states: [
              State {
                  name: "hover"
                  when: ma.containsMouse
                  PropertyChanges {
                      control.color: "blue"
                  }
               },
               State {
                   name: "press"
                   when: ma.containsPress
                   PropertyChanges {
                       control.color: "red"
                   }
               }]
          transitions: [
              Transition {
                  // from: <default state>
                  to: "hover
                  ColorAnimation{ /* some special settings */ }
              },
              Transition {
                  from: "hover"
                  to: "press"
                  ColorAnimation{ /*other special settings */ } 
              }, // other Transitions
              ]
          MouseArea {
              id: ma
              hoverEnabled: true
          }
      }
      

      As you can see here, I want to customize the state trainsition among default, hover and press. However, I have no clue to deal with these states. You might advise me to create a new state called default. However, the color of control might be changed by user, that is, I cannot do like

      State {
          name: "default"
          PropertyChanges {
               control.color: constrol.color // ????
          }
      }
      

      Anyone can help?

      B Offline
      B Offline
      Bob64
      wrote on last edited by
      #2

      @Kamichanw Can you add a property to your component that defines the default colour?

      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