Unsolved 2018 and still no solution for 90° rotated text labels with antialiasing?
-
Is there still no easy way of rotating a QLabel containing text? I can use QPixmap, sure, but what about antialiasing? I know this has been asked before but that was during Qt 4.x, maybe in 5.10 there should be something convenient!
-
@UrbanCee do you know how this could be solved? Is there any code you can contribute to the Qt Project?
-
-
So you mean subclassing QLabel and change Painter in there? Or is it possible to change the painter from a Widget from the outside?
-
@UrbanCee said in 2018 and still no solution for 90° rotated text labels with antialiasing?:
So you mean subclassing QLabel and change Painter in there? Or is it possible to change the painter from a Widget from the outside?
Using QPainter involves subclassing a widget and reimplementing
paintEvent()
.Note: I haven't tried this myself; this is just an idea. This approach will involve calculating the the coordinates and size of the text to be painted, using values of various QLabel properties.
-
I C. I wanted to avoid that. Thought there would be an easier way.
-
In the development mailing list propose adding a
transformation
property that is applied automatically to the painter for the widgets when they paint their contents, see what people think and submit a suggestion/patch to the framework would be the way such a thing gets included. A user forum is the wrong place to request features. -
@UrbanCee said in 2018 and still no solution for 90° rotated text labels with antialiasing?:
Thought there would be an easier way.
Not with QLabels, unfortunately. As @kshegunov said, make a feature request if you feel strongly about it.
You mentioned that the QPixmap workaround has antialiasing issues. A possible alternative is to use an SVG file with a QSvgWidget instead of QPixmap.
-
If the size of the QLabel is square and it only rotates 90/180/270 degrees, it can be simplified as follows.
Otherwise, as @JKSH said, you must calculate and process the changed size after rotation of the QLabel.like this:
void MyLabel::initPainter(QPainter *painter) const { painter->translate(rect().center()); painter->rotate(90); painter->translate(-rect().center()); }