Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. My button's color seems transparent but why?

My button's color seems transparent but why?

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
6 Posts 3 Posters 358 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.
  • B Offline
    B Offline
    bladekel
    wrote on last edited by
    #1

    I'm using QTDesigner 5.15.8 and trying to color buttons.
    Here is a screenshot of my problem.
    color.png

    I have inserted one button and frame on my mainwindow.
    Here is the stylesheet code of mainwindow

    QPushButton{
    background-color: red;
    }
    QFrame{
    background-color: red;
    }
    

    They are same but as you see they look different. I couldnt find why it happened but it happens even if I created a new project...

    Pl45m4P 1 Reply Last reply
    0
    • B bladekel

      I'm using QTDesigner 5.15.8 and trying to color buttons.
      Here is a screenshot of my problem.
      color.png

      I have inserted one button and frame on my mainwindow.
      Here is the stylesheet code of mainwindow

      QPushButton{
      background-color: red;
      }
      QFrame{
      background-color: red;
      }
      

      They are same but as you see they look different. I couldnt find why it happened but it happens even if I created a new project...

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      @bladekel

      Because it is how your OS draws a button.
      Don't use a stylesheet on a QPushButton if you want your "button" to be just a plain red rectangle or square.
      Make your own subclass of QPushButton and use a painter to draw the rectangle yourself.


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bladekel
        wrote on last edited by
        #3

        @Pl45m4
        On my previous project I can do what I want. I can add a new pushbutton and can color with stylesheet to whatever color I want...
        But on newer project I cant do ....

        Pl45m4P 1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          It's the gradient from the fusion style what you're seeing here I would guess.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          1
          • B bladekel

            @Pl45m4
            On my previous project I can do what I want. I can add a new pushbutton and can color with stylesheet to whatever color I want...
            But on newer project I cant do ....

            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by
            #5

            @bladekel

            Does your old project use the same Windows style?
            "Fusion" as mentioned by @Christian-Ehrlicher

            Either change that or make your own button class and draw the plain rect you want.


            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            1 Reply Last reply
            0
            • B Offline
              B Offline
              bladekel
              wrote on last edited by
              #6

              I found the solution. The reason is border....
              Thanks for all...

              ~~Warning: If you only set a background-color on a QPushButton, the background may not appear unless you set the border property to some value. This is because, by default, the QPushButton draws a native border which completely overlaps the background-color. For example,
              QPushButton { background-color: red; border: none; }
              See Customizing QPushButton for an example. ~~

              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