How to make the border have specific length in stylesheet
-
wrote on 18 Jan 2024, 14:17 last edited by
-
Hi,
AFAIK, you can't with stylesheet. You will have to paint that yourself.
-
wrote on 18 Jan 2024, 20:40 last edited by CPPUIX
Hi,
I think I have something for you, which is a trick I found to achieve that as well. I'm not sure I could call it a solution, but I think it might be what you need.
As described in my answer on Stack Overflow — How to get bracket style border for QWidget using stylesheets, you could use
QLinearGradient
:background-color: rgb(255, 255, 255); border: 5px solid qlineargradient(spread: pad,x1:0, y1:0, x2:1, y2:0, stop: 0 green, stop: 0.2 green, stop: 0.21 white, stop: 0.8 white, stop: 0.81 green stop: 1 green); border-left: 5px solid green; border-right: 5px solid green;
Just adjust the stops values and the colors, and see if it works for you.
Important: there needs to be a small fraction separating them to achieve a solid color.
Hope it helps!
-
Hi,
I think I have something for you, which is a trick I found to achieve that as well. I'm not sure I could call it a solution, but I think it might be what you need.
As described in my answer on Stack Overflow — How to get bracket style border for QWidget using stylesheets, you could use
QLinearGradient
:background-color: rgb(255, 255, 255); border: 5px solid qlineargradient(spread: pad,x1:0, y1:0, x2:1, y2:0, stop: 0 green, stop: 0.2 green, stop: 0.21 white, stop: 0.8 white, stop: 0.81 green stop: 1 green); border-left: 5px solid green; border-right: 5px solid green;
Just adjust the stops values and the colors, and see if it works for you.
Important: there needs to be a small fraction separating them to achieve a solid color.
Hope it helps!
@Abderrahmene_Rayene
A creative solution! The inventors ofQStyleSheet
would probably have said "doesn't work" - and be surprised. -
Hi,
I think I have something for you, which is a trick I found to achieve that as well. I'm not sure I could call it a solution, but I think it might be what you need.
As described in my answer on Stack Overflow — How to get bracket style border for QWidget using stylesheets, you could use
QLinearGradient
:background-color: rgb(255, 255, 255); border: 5px solid qlineargradient(spread: pad,x1:0, y1:0, x2:1, y2:0, stop: 0 green, stop: 0.2 green, stop: 0.21 white, stop: 0.8 white, stop: 0.81 green stop: 1 green); border-left: 5px solid green; border-right: 5px solid green;
Just adjust the stops values and the colors, and see if it works for you.
Important: there needs to be a small fraction separating them to achieve a solid color.
Hope it helps!
wrote on 20 Jan 2024, 22:57 last edited by@Abderrahmene_Rayene smart!
2/5