4

In PyQt's designer tool, when you create a QPushButton, at first, it will look like this: pic 1

If you right-click on it, pick 'Change stylesheet' and change the button background color to orange, for example, you'll get this:

pic 2

If you notice, the button's shape changed slightly, it's edges became more sharp and even the 'click' makes it look more 'squared' and I don't want that. I want it to look like before but just with the background set to orange. Is this possible? As an alternative, is there a way so make the edges rounder?

Thank you.

1
  • Doing what you say should just change the color.
    – Jérôme
    Commented Apr 28, 2016 at 14:44

2 Answers 2

9

You can get the effect you want by setting the radius of the border in the stylesheet, like so:

border-radius: 15px

Edit: I guess I spoke to soon. I tried it out myself and it does not have the desired effect when you have set a background color. There is some other weird stuff that happens when you change the color; it removes some other default styling that you will need to add back in manually if you want it to look similar to how it did before.

Try adding the following into the QPushButton's stylesheet, and play around with the numbers to see how they affect the button:

background-color: orange;
border-style: outset;
border-width: 2px;
border-radius: 15px;
border-color: black;
padding: 4px;

You may also need to set up some style changes for when the button is pushed (e.g. change the border-style to inset on pressed)

1

you can use more safer way using QPalette

palette = button.palette()
palette.setColor(QtGui.QPalette.Button, QtGui.QColor('orange'))
button.setPalette(palette)

Not the answer you're looking for? Browse other questions tagged or ask your own question.