Results 1 to 2 of 2

Thread: CSS in QTextBrowser

  1. #1
    Join Date
    Jan 2006
    Posts
    13
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default CSS in QTextBrowser

    Any idea how to load CSS from a resource into a QTextBrowser? I'm completely failing to load CSS into a QTextBrowser. What DOES work is inline styling the tags individually, but I really don't want to do that. I want one .css file for the whole documentation that I am preparing. Does anybody have any suggestions?

    main.cpp
    Qt Code:
    1. #include "ui_help.h"
    2. #include <QtGui>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication app(argc, argv);
    7. app.setQuitOnLastWindowClosed(true);
    8.  
    9. QMainWindow *form = new QMainWindow;
    10. Ui::MainWindow ui;
    11. ui.setupUi(form);
    12. ui.textBrowser->setSource(QString("qrc:/index"));
    13. form->show();
    14. return app.exec();
    15. }
    To copy to clipboard, switch view to plain text mode 

    help.qrc
    Qt Code:
    1. <RCC>
    2. <qresource prefix="/" >
    3. <!-- IMAGES -->
    4. <file>img/help.png</file>
    5. <file>img/home.png</file>
    6. <file>img/next.png</file>
    7. <file>img/previous.png</file>
    8. <!-- HELP DATA -->
    9. <file alias="css">help/css/main.css</file>
    10. <file alias="index">help/index.html</file>
    11. <file alias="page2">help/page2.html</file>
    12. </qresource>
    13. </RCC>
    To copy to clipboard, switch view to plain text mode 

    main.css
    [HTML]
    body {
    background: #000;
    color: #fff;
    }

    h1 {
    color: red;
    }
    [/HTML]

    index.html
    [HTML]
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-2" />
    <title>MUDtools Help</title>
    <style type="text/css">@import url(":/css");</style>
    </head>
    <body>
    <h1>MUDtools Help</h1>
    <a href=":/page2">Page 2</a>
    <br />
    <img src=":/img/help.png" />
    </body>
    </html>
    [/HTML]

    I've also tried doing:
    [HTML]
    <link href=":/css" rel="stylesheet" type="text/css" />
    [/HTML]
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: CSS in QTextBrowser

    QTextBrowser doesn't handle external css. It's a text browser not a web browser

Similar Threads

  1. link from QTextBrowser to QWebView
    By lamera in forum Qt Programming
    Replies: 4
    Last Post: 12th October 2008, 16:46
  2. Replies: 1
    Last Post: 5th August 2008, 21:44
  3. QTextBrowser: Cannot open
    By veda in forum Qt Programming
    Replies: 3
    Last Post: 27th December 2007, 13:05
  4. qtextbrowser stop scrolling on append
    By tpf80 in forum Qt Programming
    Replies: 2
    Last Post: 16th September 2007, 21:28
  5. [QT4] QtextBrowser and image size (win)
    By sebgui in forum Qt Programming
    Replies: 0
    Last Post: 28th March 2006, 22:01

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.