PDA

View Full Version : Vertical QLabel



ToddAtWSU
11th September 2006, 21:35
I want to use a QLabel to display along a vertical axis in a 2-D plot I am drawing. Since this is for a y-axis label, I want the text to be written vertically, one letter on top of another. :o Is there a simple way to do this but setting the orientation of the label or something or is the only way to add a new line after each character? I didn't know if there might be some HTML code or something I could do this with either? Thanks for your help!

wysota
11th September 2006, 21:39
On top of the other or rotated 90 deg? If the former then simply use QPainter::drawText to draw the letters one by one and help yourself with QFontMetrics to calculate the size hint of the label. For the latter either use drawText() or use QTextDocument interface to layout the text (although it is more complicated).

ToddAtWSU
12th September 2006, 13:17
I want my label to show something like this:


Y
A
X
I
S

I am thinking the QPainter method should work. I was thinking last night that I could possibly rotate using the QMatrix by pushing and popping the matrix. But I think I like the idea of QPainter better! :D Thanks for your help and please confirm that QPainter is the easier way of doing my example in the code box. Thanks!

jpn
12th September 2006, 13:25
How about

label->setText("Y\nA\nX\nI\nS");
? :)

ToddAtWSU
12th September 2006, 14:14
I just talked to the person that tasked me to do this and I guess they want the label to be rotated 90 degrees instead of one letter on top of the other. Also, JPN, I was trying to find other ways than using newlines to put the letters one on top of the other but now I realize this is not what they want anyways. But I think using QPainter::rotate( ) should work. Thanks again!