I can change the top, left, right and bottom of borders using the setStyleSheet funcion:
self.button1.setStyleSheet("""border-bottom: 1px solid #654321; border-top: 1px solid #123456""")
and this creates a button like so:
However is it possible to create borders like the one below using qss stylesheets:
Where the bottom border in only not starting at the very edge.
CodePudding user response:
Well, it is possible, but only whenever the following aspects are respected and considered:
- both vertical borders are always explicitly hidden (
border-left
andborder-right
are set tonone
); - the
border radius
is only specified for the bottom corners, and it only sets the horizontal radius, while leaving the vertical one to 0; - this is a "hack" that specifically uses geometry aspects and only works if the above are respected;
bottomMargin = 24
self.button1.setStyleSheet("""
QAbstractButton {{
border: 1px solid black;
border-left: none;
border-right: none;
border-bottom-left-radius: {margin}px 0;
border-bottom-right-radius: {margin}px 0;
}}
""".format(margin=bottomMargin)