QTextEdit doesn't display its corner with border-radius
-
Hello,
My problem is that I can't make my subclass of QTextEdit have rounded borders.
Because when I use the stylesheet property border-radius, the corners are not displayed.// In my TextEdit constructor : setStyleSheet("border: 1px solid; border-radius:10px;");
ScreenShot
I use Windows 10 with Qt5.5.1
I hope you will be able to help me...
(and sorry for the bad english, I'm french ^^) -
Hi, welcome to devnet.
Looks like a small bug in the way stylesheets are applied. You can workaround it by explicitly setting a background color:
setStyleSheet("border: 1px solid; border-radius:10px; background-color: palette(base); ");
-
@Chris-Kawa It works ! Thanks for all ^^
-
@Chris-Kawa Why is it useless to set border-radius for QTextEdit without setting a background? It's confusing to me.
-
Apparently changing just border radius does not internally trigger changing a style from the native one to stylesheets. Like I said - could be a bug. Have a look at the source code of QWidget and setStyleSheet if you're interested.
-
@Chris-Kawa Thanks. But why it is useful for QLabel.
-
@Gaobo Sorry, I don't understand the question. Why is it useful? It's your label. How should I know why it is useful to you?
-
@Chris-Kawa Sorry for my poor expresson. I mean, it's useful that I only set the border-radius for QLabel and not the background.
-
@Chris-Kawa
I found QScrollArea has the same question, but explicitly setting a background color does not work for QScrollArea.QScrollArea { border: 1px solid silver; border-radius: 10px; background-color: palette(base); }
Could you please give me some tips on this? Thanks.
-
@funway It's a bit different issue. Setting border radius does not clip children painting to the rounded corners of the parent (I'm guessing for performance reasons).
Scroll area has a viewport widget and (optionally) scrollbars that stick to the edges of it, so they will always cover the parent's rounded corners.The easiest I think would be to disable the scroll area's border entirely and place it in a container widget that has border with rounded corners and matching content margins set. This of course means that you would get a bit of empty space around the scroll area.
If that's not an option you could maybe add a transparent for input widget on top of the scroll area (or 4 small ones in the corners) and draw the rounded corners in it. That should get you what you want but is a bit more work. Note that the rounded corner would cover scrollbars, which in some styles might not look too good.
-
@Chris-Kawa Wow! Thanks for your detailed reply. I will try it. 🙏
-