Results 1 to 10 of 10

Thread: Html link color

  1. #1
    Join Date
    Feb 2006
    Posts
    60
    Thanks
    21
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Html link color

    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

  2. #2
    Join Date
    Feb 2006
    Posts
    60
    Thanks
    21
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default color links

    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

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Html link color

    Please, don't double post.

    Have you tried: <a style="text-color: gray" href="two.html">tow</a>

  4. #4
    Join Date
    Feb 2006
    Posts
    60
    Thanks
    21
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Html link color

    hi,
    Thanks for the reply,
    I tried your suggestion, but it did not work.

    bye,
    sree

  5. #5
    Join Date
    Feb 2006
    Location
    Österreich
    Posts
    35
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Html link color

    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.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Html link color

    It looks like QTextBrowser tries to be smarter than the programmer:
    Qt Code:
    1. #include <QApplication>
    2. #include <QTextBrowser>
    3. #include <QtDebug>
    4.  
    5. int main( int argc, char **argv )
    6. {
    7. QApplication app( argc, argv );
    8.  
    9. QTextBrowser browser;
    10. browser.setHtml( "<html><body><a href=\"xxx.html\" style=\"text-color:red\">XXX</a></body></html>" );
    11. qDebug() << browser.toHtml();
    12. browser.show();
    13.  
    14. return app.exec();
    15. }
    To copy to clipboard, switch view to plain text mode 
    Output:
    html Code:
    1. <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.

  7. #7
    Join Date
    Feb 2006
    Location
    Österreich
    Posts
    35
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Html link color

    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.
    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.

  8. #8
    Join Date
    Feb 2006
    Posts
    60
    Thanks
    21
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Html link color

    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

  9. #9
    Join Date
    Feb 2006
    Posts
    60
    Thanks
    21
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Html link color

    hi,
    The bug is removed in QT 4.1.1. the attribute in style is color and not text-color

    bye,
    sreedhar

  10. #10
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Html link color

    Qt Code:
    1. 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.

Similar Threads

  1. how to change backgroup color, button color and shape?
    By lzha022 in forum Qt Programming
    Replies: 10
    Last Post: 16th June 2008, 22:25
  2. Change color of a link in QLabel using Style Sheets?
    By codeslicer in forum Qt Programming
    Replies: 2
    Last Post: 15th April 2008, 11:00
  3. QLabel link color
    By dragon in forum Qt Programming
    Replies: 1
    Last Post: 17th October 2007, 07:09
  4. Loading images in html in a QTextBrowser
    By BasicPoke in forum Newbie
    Replies: 1
    Last Post: 6th June 2007, 21:51
  5. QPrinter::PdfFormat html format && Link
    By patrik08 in forum Qt Programming
    Replies: 2
    Last Post: 8th April 2007, 12:37

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.