ricky
ricky

Reputation: 2108

Qt: Draw text in vertical direction with QPainter?

How to use QPainter.drawText() API to display text in vertical direction?

The meaning of vertical direction is:

A
B
C

not like below:

enter image description here

Upvotes: 2

Views: 1187

Answers (1)

eyllanesc
eyllanesc

Reputation: 243907

The solution is to insert endline (\n) between each character as shown below:

QPainter painter(this);
QString str = "ABCDEFG";
for (int i = 1; i < str.size(); i+=2)
    str.insert(i, '\n');
painter.drawText(rect(), Qt::AlignCenter ,str);

Output:

enter image description here

Upvotes: 1

Related Questions