PDA

View Full Version : CSS in QTextBrowser



gesslar
4th April 2006, 02:24
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


#include "ui_help.h"
#include <QtGui>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
app.setQuitOnLastWindowClosed(true);

QMainWindow *form = new QMainWindow;
Ui::MainWindow ui;
ui.setupUi(form);
ui.textBrowser->setSource(QString("qrc:/index"));
form->show();
return app.exec();
}


help.qrc


<RCC>
<qresource prefix="/" >
<!-- IMAGES -->
<file>img/help.png</file>
<file>img/home.png</file>
<file>img/next.png</file>
<file>img/previous.png</file>
<!-- HELP DATA -->
<file alias="css">help/css/main.css</file>
<file alias="index">help/index.html</file>
<file alias="page2">help/page2.html</file>
</qresource>
</RCC>


main.css


body {
background: #000;
color: #fff;
}

h1 {
color: red;
}


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


I've also tried doing:


<link href=":/css" rel="stylesheet" type="text/css" />

wysota
4th April 2006, 09:17
QTextBrowser doesn't handle external css. It's a text browser not a web browser :)