Why the help document does not have a complete example of HTML? I think it's completely guesswork to use it. It seems that it's not completely compatible with html4
-
@duncan98 said in Why the help document does not have a complete example of HTML? I think it's completely guesswork to use it. It seems that it's not completely compatible with html4:
@jsulm
I know standard HTML, but qt HTML is very confusingI have done HTML for many, many years, so I know it too. What is your actual issue with the subset of HTML supported by Qt, e.g. in a
QTextEdit
?You can copy the whole of the HTML content from the https://code.qt.io/cgit/qt/qtbase.git/tree/examples/widgets/richtext/textedit/example.html?h=5.14 example you refer to as a "mess", and as well as pasting it into a
QTextEdit
to look at it you can also save it to an.html
file and open it in your web browser. Since it looks pretty similar there, you know it must be reasonably close to HTML. You can use the browser's F12 or your favorite HTML editor to examine the HTML. -
@duncan98
What is your question? You can print from aQTextDocument
. It supports precisely the HTML subset we have referenced above. If your content fits into that subset it will work, if your content goes beyond that into non-supported HTML constructs it will not (probably just ignore them). That's just how it is.If you want full HTML support you would need to move to using
QtWebEngine
. You can print from there too, which would then support full HTML. You can arrange for the content of aQTextDocument
to go into aQWebEnginePage
if desired. But your originalQTextDocument
is still liable to be limited to the Qt-supported richtext-HTML subset. -
@duncan98 said in Why the help document does not have a complete example of HTML? I think it's completely guesswork to use it. It seems that it's not completely compatible with html4:
I want to use qtextdocument to print out the data, which will be in HTML format
Please:
- Describe your requirements in more detail.
- Show us what you have tried and didn't work.
If you already have another topic that describes that, give us a link to that topic.
This topic is about the documentation. Has your question about documentation been answered? If so, close the topic.
-
Hi
You mean like this ?
https://forum.qt.io/topic/78143/export-a-qtablewidget-in-pdf -
@duncan98
What about the accepted solution in https://stackoverflow.com/questions/45467942/how-can-i-print-a-qwidget-in-qt ? The point isQWidget::render()
to a painter/paint device which is the desiredQPrinter
. See https://doc.qt.io/qt-5/qtprintsupport-index.html#printing-widgets.If you decide you want to do it by generating an HTML document into a
QDocument
off theQTableWidget
after all, see alternatively e.g. https://stackoverflow.com/questions/56605601/using-qt5-how-can-i-print-a-qtablewidget-and-scale-a-table-to-fit-onto-one-side. I went for this approach off anyQTableView
/model with rows & columns myself, so it's generic, I can use stylesheets for printing, I can export to PDF/CSV/XLSX, etc. One issue about printing theQTableWidget
as-is is that you get e.g. the column widths/truncation etc. you see on the screen, which may not be desirable, depending on your usage.