Results 1 to 3 of 3

Thread: Hardcoded fonts in Qt designer

  1. #1
    Join Date
    Apr 2009
    Posts
    32
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    6

    Default Hardcoded fonts in Qt designer

    On Ubuntu 11.04:

    • Start Designer and use the basic widget template
    • Add a QLabel.
    • Right-click the label and enter rich-text editing
    • Add some text with a superscript.


    Now click the source tab. This is what I find:

    Qt Code:
    1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
    2. <html><head><meta name="qrichtext" content="1" /><style type="text/css">
    3. p, li { white-space: pre-wrap; }
    4. </style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;">
    5. <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">A<span style=" vertical-align:super;">2</span></p></body></html>
    To copy to clipboard, switch view to plain text mode 

    Now, do perform the same exercise on Windows 7. Then the rich-text source will look like this:

    Qt Code:
    1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
    2. <html><head><meta name="qrichtext" content="1" /><style type="text/css">
    3. p, li { white-space: pre-wrap; }
    4. </style></head><body style="
    5. font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400;
    6. font-style:normal;">
    7. <p style=" margin-top:0px; margin-bottom:0px;
    8. margin-left:0px; margin-right:0px; -qt-block-indent:0;
    9. text-indent:0px;"><span style="
    10. font-size:8pt;">A</span><span style=" font-size:8pt;
    11. vertical-align:sub;">1</span></p></body></html>
    To copy to clipboard, switch view to plain text mode 

    So the fonts in the rich text is hard coded. Now, if you work in a cross-platform development where developers (on different OS's ie.) share UI files via a GIT repository, this quickly becomes a mess.

    Any suggestions?

    Maybe preprocess all .ui files and chop out the line:

    Qt Code:
    1. <body style="font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">
    To copy to clipboard, switch view to plain text mode 

    Best regards

  2. #2
    Join Date
    Nov 2010
    Posts
    315
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanked 53 Times in 51 Posts

    Default Re: Hardcoded fonts in Qt designer

    Just use source tab ONLY! Trash the heade leave only body intact.
    It will work. No problems with merging when using source tab only (remove also body and page tag).

    Problem comes from QTextDocument and that QTextDocument::setHtml accept simple html but after that QTextDocument::toHtml returns an extra header.

    Edit: In fact it works only if you set text value using property inspector and dont touch that text difrent way (that sucks), so don't click the label.
    Last edited by MarekR22; 26th January 2012 at 21:34.

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

    Default Re: Hardcoded fonts in Qt designer

    Don't insert rich text from within Designer but rather from C++ code. Makes more sense anyway (usually).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. About Fonts
    By QbelcorT in forum Qt Programming
    Replies: 1
    Last Post: 2nd April 2009, 17:58
  2. How to use qpf fonts
    By yagabey in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 18th September 2008, 07:56
  3. Translating non-hardcoded string
    By C167 in forum Qt Programming
    Replies: 2
    Last Post: 26th June 2008, 13:34
  4. Replies: 1
    Last Post: 22nd January 2007, 12:13
  5. How to improve fonts in designer ?
    By probine in forum Qt Tools
    Replies: 3
    Last Post: 25th October 2006, 20:38

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.