Qt-interest Archive, March 2008
xml in QTextBrowser
Message 1 in thread
Hello,
I'm trying to show xml files in a QTextBrowser but I've two problems:
First, the tags of the xml doument are not showed, only the content of the
tags, whithout any structure or format, like this:
VCC45 C 0.25 P trueweather1204801097.....
Second, I've tried to use xml style sheet, I don't get errors but the style
is ignored, I do it in this way:
browser->setStyleSheet((browser->loadResource(QTextDocument::StyleSheetResource,QUrl(doc
+ "/style/xml.css")).toString()));
Somebody can help me? Thank you
this is the xml file:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?><?xml-stylesheet
href="xml.css" type="text/css"?><experimentos xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="
Experimentos.xsd"><experimento>VC</experimento><algsAprendizaje><elemento>C45
C 0.25 P
true</elemento></algsAprendizaje><instanciasHipotesis>weather</instanciasHipotesis><fecha>1204801097</fecha><algBase>-1</algBase><estratificado>0</estratificado><numParticiones>2</numParticiones><numRepeticiones>1</numRepeticiones><resultadosAlgoritmo><resultadoAlgoritmo><algoritmos>C45
C 0.25 P true</algoritmos><desviacEstandar>0.0714286
</desviacEstandar><media>0.642857
</media><valorTstudent>-1</valorTstudent><porcentajeConfianza>-1</porcentajeConfianza><resultados><resultado><numInstancias>7</numInstancias><prediccion><elemento>no</elemento><elemento>no</elemento><elemento>no</elemento><elemento>no</elemento><elemento>no</elemento><elemento>no</elemento><elemento>no</elemento></prediccion><distribucionProbabilidades><lista><elemento>0</elemento><elemento>1</elemento><elemento>0</elemento><elemento>1</elemento></lista><lista><elemento>1</elemento><elemento>0</elemento><elemento>0</elemento><elemento>0</elemento></lista><lista><elemento>1</elemento><elemento>0</elemento><elemento>1</elemento><elemento>1</elemento></lista><lista><elemento>1</elemento><elemento>1</elemento><elemento>1</elemento><elemento>0</elemento></lista><lista><elemento>0</elemento><elemento>0</elemento><elemento>1</elemento><elemento>0</elemento></lista><lista><elemento>0</elemento><elemento>0</elemento><elemento>0</elemento><elemento>1</elemento></lista><lista><elemento>0</elemento><elemento>0</elemento><elemento>1</elemento><elemento>0</elemento></lista></distribucionProbabilidades><tasaError>
0.714286
</tasaError><particion>0</particion><repeticion>0</repeticion><indicesInstancias>2,3,6,10,12,5,13</indicesInstancias></resultado><resultado><numInstancias>7</numInstancias><prediccion><elemento>no</elemento><elemento>no</elemento><elemento>no</elemento><elemento>no</elemento><elemento>no</elemento><elemento>no</elemento><elemento>no</elemento></prediccion><distribucionProbabilidades><lista><elemento>0</elemento><elemento>1</elemento><elemento>0</elemento><elemento>1</elemento></lista><lista><elemento>1</elemento><elemento>0</elemento><elemento>0</elemento><elemento>0</elemento></lista><lista><elemento>1</elemento><elemento>0</elemento><elemento>1</elemento><elemento>1</elemento></lista><lista><elemento>1</elemento><elemento>1</elemento><elemento>1</elemento><elemento>0</elemento></lista><lista><elemento>0</elemento><elemento>0</elemento><elemento>1</elemento><elemento>0</elemento></lista><lista><elemento>0</elemento><elemento>0</elemento><elemento>0</elemento><elemento>1</elemento></lista><lista><elemento>0</elemento><elemento>0</elemento><elemento>1</elemento><elemento>0</elemento></lista></distribucionProbabilidades><tasaError>
0.571429
</tasaError><particion>1</particion><repeticion>0</repeticion><indicesInstancias>4,8,9,11,1,7,0</indicesInstancias></resultado></resultados></resultadoAlgoritmo></resultadosAlgoritmo></experimentos>
Message 2 in thread
Hello Laura,
Am Donnerstag, den 06.03.2008, 13:49 +0100 schrieb Laura Lozano:
> I'm trying to show xml files in a QTextBrowser but I've two problems:
>
> First, the tags of the xml doument are not showed, only the content of
> the tags, whithout any structure or format, like this:
> VCC45 C 0.25 P trueweather1204801097.....
How do you feed the xml text into the browser? Did you try to use
void setPlainText(const QString &text)
(which is inherited by QTextEdit, I think)?
Perhaps, this is a starting point, to view the complete xml code.
Best regards,
Eckard
--
[ signature omitted ]
Message 3 in thread
yes, using setPlainText the complete xml code is displayed, but I need also
to set a style sheet to de xml code, I've tried in this way but it doesn't
works:
browser->setStyleSheet((browser->loadResource(QTextDocument::StyleSheetResource,QUrl(doc
+ "/style/xml.css")).toString()));
Thank you.
2008/3/6, Eckard Riedenklau <eriedenk@xxxxxxxxxxxxxxxxxxxxxxxx>:
>
> Hello Laura,
>
> Am Donnerstag, den 06.03.2008, 13:49 +0100 schrieb Laura Lozano:
>
> > I'm trying to show xml files in a QTextBrowser but I've two problems:
> >
> > First, the tags of the xml doument are not showed, only the content of
> > the tags, whithout any structure or format, like this:
> > VCC45 C 0.25 P trueweather1204801097.....
>
>
> How do you feed the xml text into the browser? Did you try to use
> void setPlainText(const QString &text)
> (which is inherited by QTextEdit, I think)?
>
> Perhaps, this is a starting point, to view the complete xml code.
>
> Best regards,
>
> Eckard
>
>
Message 4 in thread
Am Montag, den 10.03.2008, 17:18 +0100 schrieb Laura Lozano:
> yes, using setPlainText the complete xml code is displayed, but I need
> also to set a style sheet to de xml code, I've tried in this way but
> it doesn't works:
>
> browser->setStyleSheet((browser->loadResource(QTextDocument::StyleSheetResource,QUrl(doc + "/style/xml.css")).toString()));
The documentation says, that setStyleSheet sets the style sheet for the
widget (an instance of QTextBrowser) and not the displayed text.
Depending on what you want the style sheet to do, have a look at
QSyntaxHighlighter and implement the style sheet "by hand". There is
also a nice example explaining QSyntaxHighlighter.
If you want to got further than "simple" syntax highlighting, you have
to dive into text rendering quite deep, to implement all your needed
rendering functionalities. That'll be quite complex and time-consuming.
But perhaps you should wait until Qt 4.4 is released. As far as I know,
in 4.4 WebKit will be included. WebKit is a real and complete browser
engine (e.g. Apple's Safari uses it), far more powerful than a simple
QTextBrowser. I strongly believe, that WebKit will satisfy all your
needs.
I hope, this helps a bit.
Best regards,
Eckard
--
[ signature omitted ]