PDA

View Full Version : Vertical label text



Maxxximo
24th January 2020, 12:29
Hi all,
I searched the forum, but couldn't find a similar post on this topic.

What I need is a way to orient the text of a label in vertical, i.e. up towards down or vice versa.
I guess I won't be using a layout, since the label must be precisely positioned by the user over a background bitmap (I can use setGeometry()).

Any hints will be appreciated.

Massimo

d_stranz
24th January 2020, 16:13
A QLabel widget supports only horizontal text. If you can use QGraphicsScene to compose your bitmap + label, then you could use QGraphicsPixmapItem to contain the image, and a QGraphicsTextItem (with rotation) for the text. If the letters have to be stacked:

M
y
L
a
b
e
l

instead of simply rotated, then you can derive from QGraphicsTextItem and override the paint(), boundingRect(), and other methods as required.

Maxxximo
24th January 2020, 17:08
Thanks for your reply, but why are you asking if I CAN use QGraphicsScene?
Can you point me to a sample showing these QGraphics classes?

Thanks

d_stranz
24th January 2020, 17:32
Can you point me to a sample showing these QGraphics classes?

Qt comes with a huge variety of example projects and tutorials, including many for the Graphics / View framework (https://doc.qt.io/qt-5/graphicsview.html). I'd suggest you start there and let Google be your friend.