Results 1 to 2 of 2

Thread: Position of text in a qlabel

  1. #1
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Position of text in a qlabel

    Hi,
    I have created a custom label where text is compressed if wider than object; here the code:

    Qt Code:
    1. void CustomLabel::paintEvent(QPaintEvent * /* event */)
    2. {
    3. QPainter *painter = new QPainter(this);
    4. painter->setRenderHints(QPainter::HighQualityAntialiasing,true);
    5. QAbstractTextDocumentLayout::PaintContext context;
    6. doc.setDefaultFont(font());
    7. doc.setHtml(text());
    8. float ratio = doc.documentLayout()->documentSize().width() / width();
    9. if(ratio > 1.0)
    10. painter->scale(1.0/ratio,1.0);
    11. doc.documentLayout()->draw(painter, context);
    12. delete painter;
    13. }
    To copy to clipboard, switch view to plain text mode 

    It works; but if I have 2 sided labels, one normal qlabel and one customlabel the text in the custom label has a base line which is lower; here a picture of what I mean: the three labels on the left are qlabels and those with bold text are customlabels



    I have used Designer to create the gui and, from designer itself, I have promoted the labels to customlabel.

    Has QLabel a property which returns text position or something else to adjust the text position in my label?

    Thanks.
    Giuseppe CalÃ

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

    Default Re: Position of text in a qlabel

    Why don't you take a look at QLabel::paintEvent() implementation and see yourself?

    PS. Attach images instead of using an external site next time, please.
    J-P Nurmi

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. QLabel - visible text function or something else
    By john in forum Qt Programming
    Replies: 3
    Last Post: 20th April 2008, 11:26
  3. QLabel, large, rich text, font size
    By TheKedge in forum Qt Programming
    Replies: 3
    Last Post: 5th February 2007, 11:56
  4. Pixel Position and Printing text
    By nErnie in forum Qt Programming
    Replies: 1
    Last Post: 7th November 2006, 12:35
  5. Setting text color on QLabel
    By Yorma in forum Newbie
    Replies: 11
    Last Post: 15th June 2006, 07:25

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.