Solved CSS styling richtext in QTextDocument
-
Qt does not support all HTML and CSS attributes - see https://doc.qt.io/qt-5/richtext-html-subset.html
/edit:
border-top-style: dotted;
should work though... will take a look. -
@Christian-Ehrlicher Hello, thank you. I know, it is what I say in the question. I use only those mentioned in supported subset as given in the link. Like width. But they do not work for some reason.
-
At least I found the reason why border-style does no longer work - it was due to https://bugreports.qt.io/browse/QTBUG-36152 which added some new capabilities (border-collapse)
-
@Christian-Ehrlicher I read it was fixed as of Qt 5.14. But I think I can live with that.
I found that the width works as attribute. At least the relative % variant.
-
I struggled with styling the html in QTextDocument. In my code I created an XML representation and then used XSLT stylesheet to convert to HTML. I am not completely satisfed with the output as I had issues making it look the way I wanted. I think I will eventually convert the XML to QML code on the fly. There were so many limitations with the HTML/CSS in QTextDocument it was very frustrating.
-
@fcarney Hello, thanks. Yes, it so limited that the use is only very basic. I am thinking of QML as well. But I never got in touch with that, and it is as learning whole new language. I do not know which way I would have to go. Well new adventure in front of me.
I am also looking at this report designer: https://sourceforge.net/projects/qtrpt/
What I like about HTML/CSS, is that everybody knows it, so it can be edited by any body who knows IT basics. I miss just few more styles and I would be happy.
-
@hullatom said in CSS styling richtext in QTextDocument:
I read it was fixed as of Qt 5.14.
You read it wrong - I said that this fix introduced the regression about not honoring the border-style when using border-collapse.
-
@Christian-Ehrlicher Maybe, it is somewhere in the text hidden? The summary on top of the page is saying:
https://bugreports.qt.io/browse/QTBUG-36152
Details
Type: Suggestion
Status:CLOSED
Priority: P4: Low
Resolution:Done
Affects Version/s:
5.2.0
Fix Version/s:
5.14.0 AlphaCreated: 13 Jan '14 22:56
Updated: 20 Aug '19 11:07
Resolved: 08 Aug '19 17:59 -
@hullatom Read:
At least I found the reason why border-style does no longer work - it was due to https://bugreports.qt.io/browse/QTBUG-36152 which added some new capabilities (border-collapse)
border-style does not work together with border-collapse.
-
-
Thank you all. In the end I managed to use the QtWebEngineView to render full html and css with no limitations.
-
@hullatom said in CSS styling richtext in QTextDocument:
render
Hi ,
I read something about xml to html conversion but am not too sure
and also thread is quite old, but if anyone knows how to convert xml to html
( qt 6.5 ) applying css -xslt , please let me know.thanks & warm regards.
~ Rudresh -
@Rudresh said in CSS styling richtext in QTextDocument:
( qt 6.5 ) applying css -xslt , please let me know.
You have to use an external library for this. Qt does not provide this functionality in Qt6.
-
@Christian-Ehrlicher
Thanks a lot Christian.