Hi,
I am a new user of QT. I want too give color to HTML links present in QTextBrowser in QT4.1. The color will change dynamically.
Regards,
Sreedhar
Hi,
I am a new user of QT. I want too give color to HTML links present in QTextBrowser in QT4.1. The color will change dynamically.
Regards,
Sreedhar
Hi,
I want to change the color of the link used in HTML in QTextBrowser. The default color is blue. Some of the links in my page will have blue, and others will be gray.
<a href="one.html">one</a> -- blue color
<a href="two.html">tow</a> -- gray color
I tried to use the <font color=gray> for surrounding the link tag or the text in the link(one or two) but that doen't work.
I will be thankful if somebody provides me the solution.
Thanks in advance,
bye,
sree
Please, don't double post.
Have you tried: <a style="text-color: gray" href="two.html">tow</a>
hi,
Thanks for the reply,
I tried your suggestion, but it did not work.
bye,
sree
Try <font color="gray"> or even <font color="#808080">. Qt HTML support recognizes both named colors and RGB values. I really doubt Qt's HTML support extends to the full W3 specification for XHTML, but it's quite possible they at least borrowed the requirement from XHTML that attributes have to always be quoted, in which case just writing <font color=gray> won't work.
My philosophy is: If you can use a free, open-source alternative: do it. And if you can't, pretend it's free and open-source and hope you don't get caught.
It looks like QTextBrowser tries to be smarter than the programmer:Output:Qt Code:
#include <QApplication> #include <QTextBrowser> #include <QtDebug> int main( int argc, char **argv ) { QTextBrowser browser; browser.setHtml( "<html><body><a href=\"xxx.html\" style=\"text-color:red\">XXX</a></body></html>" ); qDebug() << browser.toHtml(); browser.show(); return app.exec(); }To copy to clipboard, switch view to plain text modeNote the <span> tag.html Code:
<html><head>...<a href="xxx.html"><span style=" text-decoration: underline; color:#0000ff;">XXX</span></a></p></body></html>To copy to clipboard, switch view to plain text mode
That's terrible. I tried about ten different things to get it to display and the results ranged from identical to yours to Qt replacing my <a...</a> link with a "qt-paragraph-type: empty" CSS directive. I even made the HTML file external, used EXACTLY the same markup that toHTML produces except changed the color in <span> and it still changes it.
Becoming obsessed with this weirdness, I just spent the past twenty minutes searching the Qt-interest Archive. Two things struck me as funny:
1) There's about ten questions so far (but I have only reached as far back as September 2005) asking how to avoid getting your HTML mangled by TextBrowser. Not a single one of them is replied to.
2) There's a quote from 05.09.2005 which says:
To sreedhar: I guess if you want to do something as vastly complex as changing the color of a link, you'll have to create a basic richedit document and parse all of the HTML yourself.In any case: Qt only supports very limited HTML, I guess it's roughly
HTML 3.2 with some style sheet support for fonts, nothing more! This is
enough to display simple help pages with tables, images, some text
layout, hyperlinks... that's it!
My philosophy is: If you can use a free, open-source alternative: do it. And if you can't, pretend it's free and open-source and hope you don't get caught.
hi,
Thanks a lot for the reply. If i use <font color="gray"> in QT 4.0 it works fine and shows my links in gray, but if i shift to QT 4.1 and the links are displayed in blue.
So, it seems that there is no simple way to get around this. It seems to be a bug in QT4.1 as the parsing of HTML to change color of links works in QT4.0 and QT3.2.
bye,
sreedhar
hi,
The bug is removed in QT 4.1.1. the attribute in style is color and not text-color
bye,
sreedhar
Qt Code:
Click <a href=\"file.pdf\" style=\"color:#33FFFF\">here</a> for PDF file.To copy to clipboard, switch view to plain text mode
This works for QString on QLabel, fyi. Qt 4.2.3.
"text-color" didn't work; just "color" does.
Bookmarks