How do I make a circle QLabel?
Asked Answered
U

2

10

I have a QLabel that i fill in red with the stylesheet, but the QLabel is rectangular, and I want a circle. I try to add border-radius, but it doesn't work, maybe because i put my QLabel in a formLayout.

Is there a simple method to have a round QLabel by using stylesheet ?

Thanks.

EDIT : Using a picture seems more easier than doing this now.

Ulyssesumayyad answered 21/5, 2014 at 14:46 Comment(0)
K
10

I tried to use stylesheet by setting border-radius and min-width/min-height. It looks like

QLabel{
  border-radius: 10px;
  min-height: 20px;
  min-width: 20px;
}
Keck answered 4/8, 2018 at 8:36 Comment(1)
Iso min-height and min-width you need max-height and max-width for this to work properly.Goraud
L
5

Create an image that you use as a mask and set that on the label by calling setMask. As the documentation states: -

Causes only the pixels of the widget for which bitmap has a corresponding 1 bit to be visible. If the region includes pixels outside the rect() of the widget, window system controls in that area may or may not be visible, depending on the platform

Lothair answered 21/5, 2014 at 14:49 Comment(1)
This is not a very good advice since setMask is really only needed on a top level window, where the mask bitmap is passed to an obsolete GUI system such as an old X11 server or Windows 95. Even Windows XP supports alpha-blended windows (they call it "layered" windows). All that you need to do is to compose a masking circle as the last step of drawing your label. It will let you antialias the edges and avoid the jagged appearance of the window.Mano

© 2022 - 2024 — McMap. All rights reserved.