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. Best way to create a rollover buttons
Qt 6.11 is out! See what's new in the release blog

Best way to create a rollover buttons

Scheduled Pinned Locked Moved QML and Qt Quick
9 Posts 2 Posters 2.6k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hi,
    I have two images which represents the two states of a button: normal and rollover.
    I put them into a resource file and this is the first try to make such a button:

    @
    Image {
    source: mouseArea.containsMouse ? "qrc:///rollover.png" : "qrc:///normal.png"
    anchors.horizontalCenter: parent.horizontalCenter
    y: 162

        Text {
            anchors.centerIn: parent
            font.pixelSize: 60
            font.bold: true
            color: "#ffffff"
            text: "PRESS ME"
        }
    
        MouseArea {
            id: mouseArea
            anchors.fill: parent
            hoverEnabled: true
        }
    }
    

    @

    It works, but it takes few seconds to load each image (they should be cached but it takes the same time every time the mouse enters and exits).

    We are talking about files of 3-4 kBytes!
    What's wrong? What's the best way to achieve this?

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hmmm i think this is not very good idea to load the image if you need it depending on the image size it cost a lot of time :). It's better in your case to load both images and show and hide them depending in the state. Another simple way come from html and css. Put your states on one image (only works really good if the icons are nearly the same size so you define a sprite size) and use a parent Rectangle with clip activated. Depending on the state you move the image along an axis with the amount off a sprite. Sorry my english is horrible hopefully you understand what i mean. "Here":http://css-tricks.com/css-sprites/ a link to explain the second way a little bit better :)

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        Thanks, very interesting!

        However I'm afraid the problem is elsewhere (see http://qt-project.org/forums/viewthread/48610/) because I tried this:

        @
        import QtQuick 2.0

        Rectangle {
        id: root
        width: 1024
        height: 768

        Component.onCompleted: {
            root.state = "normal"
        }
        
        states: [
            State {
                name: "normal"
                PropertyChanges { target: btn; color: "yellow" }
            },
            State {
                name: "rollover"
                PropertyChanges { target: btn; color: "red" }
            }
        ]
        
        
        Rectangle {
            id: btn
            width: 600
            height: 300
        
            MouseArea {
                id: mouseArea
                anchors.fill: parent
                hoverEnabled: true
                onEntered: root.state = "rollover"
                onExited: root.state = "normal"
            }
        }
        

        }
        @

        and the color changes after 1-2 seconds the mouse enters or exits the area. Trying to write the event on console leads to an immediate changes, to the issue is only for rendering.

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          'Sorry, can't reproduce this. On my system the color change is immediately.

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            Yes I know ;-)
            On all other systems I have the color changes immediately. But just on that platform I experience such a issue and I can't understand how to fix it.

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

              Have you tried to make the rectangle smaller? Sounds a little bit like a rendering issue. Have your device enough graphic power to render this? What's your device and specs?

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #7

                Yes, it doesn't depend much about the rectangle size. The strange thing is the opengl examples runs fine, while the qml or quick ones renders as slow as my application.

                Anyway this is the board I'm working on:

                http://downloadt.advantech.com/ProductFile/PIS/ARK-1120F/Product - Datasheet/ARK-1120F_DS(07.29.14)20140729172411.pdf

                1 Reply Last reply
                0
                • ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #8

                  Hmmm strange. No debug output? Maybe missing Shaders?

                  1 Reply Last reply
                  0
                  • ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #9

                    Here you can find the debugging output with QSG_INFO=1:

                    http://qt-project.org/forums/viewthread/48610/#199687

                    without I get no warnings.

                    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