Results 1 to 3 of 3

Thread: how to set custom font to qlabel

  1. #1
    Join Date
    Jan 2015
    Posts
    35
    Thanks
    20
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default how to set custom font to qlabel

    Hi,

    I add mylabels to form programmatically.
    Now I set custom font to these labels as follow:

    1.
    QFont font("MyFont001 ", 30, QFont::Bold);
    myLabel->setFont(font);
    or

    2.
    myLabel->setStyleSheet(@"font: 9pt "MyFont001 ";");
    Both can not change to myLabels' font to MyFont001

    So I add a label at Qt Designer and change QLabel's font to my custom font. It's also same result.

    How can I set custom font (ttf font) to qlabel programmatically?
    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,418
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to set custom font to qlabel

    Have you checked the font object?

    The first approach is the canonical way to do that but maybe your font object is not the font you are expecting, e.g. your font not being available to the system's font database.

    Cheers,
    _

  3. #3
    Join Date
    Jan 2015
    Posts
    35
    Thanks
    20
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: how to set custom font to qlabel

    Thanks for your replay,

    I checked my font name in font database and I found it.

    QString fontName;
    QFontDatabase database;
    foreach (const QString &family, database.families()) {
    fontName= fontName + ";" + family;
    }
    Finally I found a error at font.

    My custom font name has a space "MyFont001 " in name. It doe not work. So I'll compile my font again.

    Thank anda_skoa.
    Last edited by binary001; 8th March 2015 at 12:49.

Similar Threads

  1. Replies: 5
    Last Post: 18th August 2014, 21:48
  2. QLabel Font size is not changing???
    By Gokulnathvc in forum Newbie
    Replies: 4
    Last Post: 22nd March 2011, 11:17
  3. Replies: 1
    Last Post: 2nd August 2008, 15:46
  4. QLabel - auto font scaling possible?
    By Byngl in forum Qt Programming
    Replies: 1
    Last Post: 11th October 2007, 16:50
  5. QLabel, large, rich text, font size
    By TheKedge in forum Qt Programming
    Replies: 3
    Last Post: 5th February 2007, 11:56

Tags for this Thread

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.