PDA

View Full Version : Hardcoded fonts in Qt designer



mpi
26th January 2012, 17:57
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:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
p, li { white-space: pre-wrap; }
</style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;">
<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>


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


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


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:


<body style="font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">

Best regards

MarekR22
26th January 2012, 21:28
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.

wysota
26th January 2012, 23:31
Don't insert rich text from within Designer but rather from C++ code. Makes more sense anyway (usually).