Results 1 to 5 of 5

Thread: Vertical QLabel

  1. #1
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Cool Vertical QLabel

    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. 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!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Vertical QLabel

    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).

  3. The following user says thank you to wysota for this useful post:

    ToddAtWSU (13th September 2006)

  4. #3
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Cool Re: Vertical QLabel

    I want my label to show something like this:

    Qt Code:
    1. Y
    2. A
    3. X
    4. I
    5. S
    To copy to clipboard, switch view to plain text mode 

    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! Thanks for your help and please confirm that QPainter is the easier way of doing my example in the code box. Thanks!

  5. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Vertical QLabel

    How about
    Qt Code:
    1. label->setText("Y\nA\nX\nI\nS");
    To copy to clipboard, switch view to plain text mode 
    ?
    J-P Nurmi

  6. The following user says thank you to jpn for this useful post:

    Cayan (31st August 2011)

  7. #5
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Cool Re: Vertical QLabel

    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!

Similar Threads

  1. [SOLVED] subclassing qlabel
    By mickey in forum Newbie
    Replies: 10
    Last Post: 4th June 2008, 14:43
  2. Subclassed QLabel and enterEvent
    By Lykurg in forum Qt Programming
    Replies: 2
    Last Post: 29th August 2006, 06:44
  3. QT4 layout of complex dialog is very slow
    By cboles in forum Qt Programming
    Replies: 15
    Last Post: 28th April 2006, 19:57
  4. how to catch enter press in QLabel?
    By Morea in forum Newbie
    Replies: 2
    Last Post: 26th March 2006, 22:53
  5. table in QLabel
    By Pan Wojtas in forum Qt Programming
    Replies: 19
    Last Post: 13th February 2006, 11:37

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.