If this is your first visit, be sure to
check out the
FAQ
by clicking the
link above. You may have to
register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.
Welcome to
Qt Centre
.
Qt Centre
is a community site devoted to programming in C++ using the
Qt framework
. Over 90 percent of questions asked here gets answered. If you are looking for information about Qt related issue —
register
and post your question.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our
free
community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please,
join our community today
!
If you have any problems with the registration process or your account login, please
contact us
.
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
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,
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.
#include <QApplication>
#include <QTextBrowser>
#include <QtDebug>
int main( int argc, char **argv )
{
browser.setHtml( "<html><body><a href=\"xxx.html\" style=\"text-color:red\">XXX</a></body></html>" );
qDebug() << browser.toHtml();
browser.show();
return app.exec();
}
#include <QApplication>
#include <QTextBrowser>
#include <QtDebug>
int main( int argc, char **argv )
QApplication app( argc, 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 mode
Output:
html Code:
Switch view
<html><head>...<a href="xxx.html"><span style=" text-decoration: underline; color:#0000ff;">XXX</span></a></p></body></html>
<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
Note the <span> tag.
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:
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!
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.
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.
sreedhar
Click <a href=\"file.pdf\" style=\"color:#33FFFF\">here</a> for PDF file.
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.