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. Disable default color on button down
Qt 6.11 is out! See what's new in the release blog

Disable default color on button down

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

    Re: Customize color on button down or active

    I believe it is this exact same issue but there was no solution for it.

    I have a function that should change the color of the button if it is being hovered over or if it is pressed.

    However, there is a default functionality for the colors of the button that seems to be taking precedence over my function.

    I was able to get the hover aspect of it working by setting flat: true but still when I press the button I get the same button down default white background.

    Here is my qml file:

    import QtQuick 2.15
    import QtQuick.Controls 2.15
    
    Button {
        id: btnToggle
    
        // CUSTOM PROPERTIES
        property url btnIconSource: "../../images/png_images/icons8-menu-rounded-90(-xxhdpi).png"
        property color btnColorDefault: "#1c1d20"
        property color btnColorMouseOver: "#23272e"
        property color btnColorClicked: "#00a1f1"
    
        QtObject {
            id: internal
    
            // MOUSE OVER AND CLICK CHANGE COLOR
            property var dynamicColor: if(btnToggle.down){
                                           btnToggle.down ? btnColorClicked : btnColorDefault
                                       } else {
                                           btnToggle.hovered ? btnColorMouseOver : btnColorDefault
                                       }
        }
    
        flat: true
        implicitWidth: 70
        implicitHeight: 60
    
        background: Rectangle {
            id: bgBtn
            color: internal.dynamicColor
    
            Image {
                id: iconBtn
                source: btnIconSource
                smooth: false
                layer.format: ShaderEffectSource.RGBA
                antialiasing: false
                anchors.verticalCenter: parent.verticalCenter
                anchors.horizontalCenter: parent.horizontalCenter
                height: 25
                opacity: 1
                visible: true
                width: 25
                fillMode: Image.PreserveAspectFit
            }
        }
    }
    

    EDIT: I noticed that i can see the color I chose for button down actually behind the white background (the blue color sticking out of the corners). So my function seems to be working but there is a color being displayed over it. See below:

    4d214480-ad7e-49bb-a7f4-218e11d5fec3-image.png

    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