QWebView doesn't display correctly unicode
I have a compiled qt embedded 4.6.2 .for arm successfully and try to run simple browser:
Code:
int main(int argc, char *argv[])
{
QWebView *view = new QWebView();
view
->load
(QUrl("/home/index.html"));
view->showFullScreen();
return a.exec();
}
I have a problem with displaying some of the unicode characters in webpages. I'm from Slovakia and we have some special characters. In my case e.g. character ľ isn't display correctly (just blank space instead). I compile qt with unicode font but it doesn't help. How can I make my web browser display correctly webpages?
Thanks,
Marek
Re: QWebView doesn't display correctly unicode
Did you set the proper html encoding tags in the file?
Re: QWebView doesn't display correctly unicode
Same webpage test on qt on desktop and it display correctly all characters.
Re: QWebView doesn't display correctly unicode
Quote:
Originally Posted by
binaural
Same webpage test on qt on desktop and it display correctly all characters.
Which means exactly nothing... The default encoding might be different or fonts may not contain proper glyphs on your embedded platform. Check the file encoding, html encoding and check whether the font can display those characters at all (i.e. by placing them on a regular QLabel).
Re: QWebView doesn't display correctly unicode
Hi,
you're right if I just use Qlabel label("Å¡Äťž") on desktop it doesn't display correctly in QLabel.
I use following code and it display correctly on desktop but not on embedded device (just empty window):
Code:
#include <QtGui/QApplication>
#include <QLabel>
#include <QTextCodec>
int main(int argc, char *argv[])
{
QString string
= codec
->toUnicode
(encodedString
);
view->setText(string);
view->show();
return a.exec();
}
I try to look to docu for qwebview and found followig method:
Code:
view->settings()->setDefaultTextEncoding("utf-8");
but have still same result (no correct output). My webpages are utf-8 encoded.Any other options to check?
Thanks in advance,
Marek
Re: QWebView doesn't display correctly unicode
Try:
Code:
#include <QtGui>
int main(int argc, char *argv[])
{
view.
setText(QString::fromUtf8("Å¡Äťž"));
view.show();
return a.exec();
}
Re: QWebView doesn't display correctly unicode
wysota: trying your code but no change (no unicode displayed on display) just empty label.
Re: QWebView doesn't display correctly unicode
Also try:
Code:
const char * web = "<html><head><title>ľšÄťžýáÃ*éäúô!!!</title><meta http-equiv=Content-Type content=\"text/html; charset=UTF-8\"></head><body bgcolor='blue'><center><H1>ľšÄťžýáÃ*éäúô</H1></center><hr>При доÑтупе к Ñайту произошла ошибка. ПожалуйÑта проверьте ваше подключение к интернету.</body></html>";
view
->setHtml
(QString::fromLocal8Bit(web,
strlen(web
)));
but in window see only chars: ýáÃ*éäúô and also no russian characters only 2 dots(.) Is there possibility that ľšÄťž aren't in any font for embedded? How can I check that?
Thanks
Re: QWebView doesn't display correctly unicode
Quote:
Originally Posted by
binaural
wysota: trying your code but no change (no unicode displayed on display) just empty label.
Are you sure the file is utf-8 encoded? Maybe it's iso-8859-2 encoded?
Re: QWebView doesn't display correctly unicode
well when open and read by python there are utf-8 encoded characters:
<html>\n<head><title>\xc4\xbe\xc5\xa1\xc4\x8d\xc5\ xa5\xc5\xbe\xc3\xbd\xc3\xa1\xc3\xad\xc3\xa9\xc3\xa 4\xc3\xba\xc3\xb4!!!</title>\n<meta http-equiv=Content-Type content=text/html; charset=UTF-8>\n</head>\n<body bgcolor='blue'>\n<center><H1>\xc4\xbe\xc5\xa1\xc4\ x8d\xc5\xa5\xc5\xbe\xc3\xbd\xc3\xa1\xc3\xad\xc3\xa 9\xc3\xa4\xc3\xba\xc3\xb4</H1></center>\n<hr>\xd0\x9f\xd1\x80\xd0\xb8 \xd0\xb4\xd0\xbe\xd1\x81\xd1\x82\xd1\x83\xd0\xbf\x d0\xb5 \xd0\xba \xd1\x81\xd0\xb0\xd0\xb9\xd1\x82\xd1\x83 \xd0\xbf\xd1\x80\xd0\xbe\xd0\xb8\xd0\xb7\xd0\xbe\x d1\x88\xd0\xbb\xd0\xb0 \xd0\xbe\xd1\x88\xd0\xb8\xd0\xb1\xd0\xba\xd0\xb0. \xd0\x9f\xd0\xbe\xd0\xb6\xd0\xb0\xd0\xbb\xd1\x83\x d0\xb9\xd1\x81\xd1\x82\xd0\xb0 \xd0\xbf\xd1\x80\xd0\xbe\xd0\xb2\xd0\xb5\xd1\x80\x d1\x8c\xd1\x82\xd0\xb5 \xd0\xb2\xd0\xb0\xd1\x88\xd0\xb5 \xd0\xbf\xd0\xbe\xd0\xb4\xd0\xba\xd0\xbb\xd1\x8e\x d1\x87\xd0\xb5\xd0\xbd\xd0\xb8\xd0\xb5 \xd0\xba \xd0\xb8\xd0\xbd\xd1\x82\xd0\xb5\xd1\x80\xd0\xbd\x d0\xb5\xd1\x82\xd1\x83.\n</body>\n</html>
so encoding should be correct.
Re: QWebView doesn't display correctly unicode
I meant the file from my example. Besides I can't really see the utf-8 encoding among this garbage :)
Re: QWebView doesn't display correctly unicode
What file you mean from your example?
OK start from beginning:
I create a file index.html with utf-8 encoding and also save file as utf-8:
Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<h1>ľšÄťžýáÃ*</h1>
</body>
</html>
The use this code to display content (web is filename):
Code:
in.setCodec("utf8");
view
->setHtml
(in.
readAll(),
QUrl("file:///home/www/"));
but on display I can see only ýáÃ*.
Re: QWebView doesn't display correctly unicode
Quote:
Originally Posted by
binaural
What file you mean from your example?
The one with the label code. I suggest you start with getting that to work.
Re: QWebView doesn't display correctly unicode
Well problem found. Problem was in font type. It seems unicode font doesn't support special characters. After enabling freetype text is correctly displayed.
Re: QWebView doesn't display correctly unicode
Quote:
Originally Posted by
binaural
It seems unicode font doesn't support special characters. After enabling freetype text is correctly displayed.
Aren't you mixing two terms here? "Unicode font" is not about font format, it's about font encoding. Freetype fonts are "unicode fonts" too.
Re: QWebView doesn't display correctly unicode
Yes maybe I wasn't precise. I was playing with fonts and if I don't compile freetype support to qt default font for displaying was family unifont (unifont_160_50.qpf). After installing truetype default font became (Dejavu Sans) which could correctly display all character which I need. I would say that unifont doesn't contain all special character.
With Dejavu Sans font text is correctly displayed but default font weight is bigger like for unifont and items are shifted. I try to change font weight by:
Code:
QFont web_font
("DejaVu Sans",
6);
qDebug() << font.weight() << " " << font.pointSize();
web_font.setPointSize(6);
web_font.setWeight(20);
view->setFont(web_font);
but there's no effect (text has same weight and size). Is there any option which I'm missing to set?
Thanks
Re: QWebView doesn't display correctly unicode
.qpf fonts are bitmap fonts. But you can generate your own .qpf from a font of your choice so I guess you can make one from DejaVu Sans and have proper glyphs available in .qpf.