Results 1 to 5 of 5

Thread: Load fonts from disk.

  1. #1
    Join Date
    Jul 2015
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Load fonts from disk.

    Environment: Qt 5.5, Win7

    I tried to insert into your QML-project custom font.

    Qt Code:
    1. FontLoader {
    2. id: customFont
    3. source: "f:/QT/MyProjects/TEST4/1.ttf"
    4. }
    5.  
    6. TextArea {
    7. font.family: customFont.name
    8. }
    To copy to clipboard, switch view to plain text mode 

    I get the message: QML FontLoader: Cannot load font: "f:/QT/MyProjects/TEST4/1.ttf"

    It turned out that this code loads fonts only from the network ( I checked it and it really works without problems )
    Please tell me how to load fonts in qml from the disk.

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

    Default Re: Load fonts from disk.

    Have you tried passing the filename as a file: URI?

    E.g. assuming that the QML file is in the same directory as the font, something like

    Qt Code:
    1. source: Qr.resolveUrl("1.ttf");
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  3. #3
    Join Date
    Jul 2015
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Load fonts from disk.

    Following your advice, I tried to place the font-file in all projects folders (that Qt found it for sure) and wrote:
    Qt Code:
    1. source: Qt.resolvedUrl("1.ttf");
    To copy to clipboard, switch view to plain text mode 
    but i got the same: QML FontLoader: Cannot load font: "qrc:/1.ttf"

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Load fonts from disk.

    Well, your QML file is apparently not loaded from disk but from the Qt resource system.
    resolveUrl() creates an URL relative to the QML file.

    You can put the font into the resource as well, or use a different way to construct the file URI for the on-disk file.

    Cheers,
    _

  5. #5
    Join Date
    Jul 2015
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Load fonts from disk.

    Quote Originally Posted by anda_skoa View Post
    Well, your QML file is apparently not loaded from disk but from the Qt resource system.
    resolveUrl() creates an URL relative to the QML file.

    You can put the font into the resource as well, or use a different way to construct the file URI for the on-disk file.

    Cheers,
    _


    Yes! After i add the font-file into the resource problem disappeared. Thanks for the help!

Similar Threads

  1. Adding Arabic fonts and CJK (China Japan Korean) fonts
    By kishore7771 in forum Qt Programming
    Replies: 0
    Last Post: 30th July 2013, 18:33
  2. Load multi language fonts at the same time
    By lllturtle in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 12th April 2012, 08:20
  3. Copying files from USB disk to System disk using GUI
    By augusbas in forum Qt Programming
    Replies: 1
    Last Post: 24th February 2010, 11:45
  4. Disk space
    By QTInfinity in forum Qt Programming
    Replies: 1
    Last Post: 31st October 2008, 16:05
  5. Help!! cannot load Fonts!
    By gattogio in forum Qt Programming
    Replies: 5
    Last Post: 24th February 2007, 13:37

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
  •  
Qt is a trademark of The Qt Company.