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. Button isn't changing it's color.
Qt 6.11 is out! See what's new in the release blog

Button isn't changing it's color.

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

    I want to create simple login screen. I set button's background and colors dempending on it's state but when i click on it I can see the red color only for a while and later it changes to deafult windows button. I tried to change highlighted, and flat property but it doesn't help. How to fix it?

    Button {
                    id: button
                    Layout.fillWidth: true
                    Layout.fillHeight: true
                    text: "A Special Button"
                    flat: true
                    highlighted: false
                    background: Rectangle {
                        Layout.fillWidth: true
                        implicitHeight: 40
                        color: button.down ? "red" : (parent.hovered ? "red" : "purple")
                        border.color: "#000101"
                        border.width: 1
                        radius: 4
                    }
                }
    

    How it looks like: when pressed:
    Screenshot 2023-02-07 211616.png

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

      Tried the same example. It is working as expected from your code. May be try with simple sample & identify the issue with your code. May be something else is modified somewhere else.

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

      A 1 Reply Last reply
      0
      • dheerendraD dheerendra

        Tried the same example. It is working as expected from your code. May be try with simple sample & identify the issue with your code. May be something else is modified somewhere else.

        A Offline
        A Offline
        Antek832
        wrote on last edited by
        #3

        @dheerendra

        I've tried to rewrite my code for button in separate project and result is still the same as earlier, when button is pressed I can see result the same as on the picture above. Any ideas?

        import QtQuick
        import QtQuick.Controls
        
        Window {
            width: 640
            height: 480
            visible: true
            title: qsTr("Hello World")
        
            Button{
                id: button
                anchors.fill: parent
                text: "click me"
                flat: true
                highlighted: false
                background: Rectangle {
                    anchors.fill: parent
                    color: button.down ? "red" : (parent.hovered ? "red" : "purple")
                }
            }
        }
        
        
        dheerendraD 1 Reply Last reply
        0
        • A Antek832

          @dheerendra

          I've tried to rewrite my code for button in separate project and result is still the same as earlier, when button is pressed I can see result the same as on the picture above. Any ideas?

          import QtQuick
          import QtQuick.Controls
          
          Window {
              width: 640
              height: 480
              visible: true
              title: qsTr("Hello World")
          
              Button{
                  id: button
                  anchors.fill: parent
                  text: "click me"
                  flat: true
                  highlighted: false
                  background: Rectangle {
                      anchors.fill: parent
                      color: button.down ? "red" : (parent.hovered ? "red" : "purple")
                  }
              }
          }
          
          
          dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
          wrote on last edited by
          #4

          @Antek832
          Can you try with simple statement like this first ?
          color: button.down ? "red" :: "purple")

          What is the result of this ?
          Which version of Qt ?

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

          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