Rich Text Format to QTextEdit
-
Hi,
I would like to display some rich text to QTextEdit but it doesn't work : it displays :
{\rtf1\adeflang1025\ansi\ansicpg1252\uc1\adeff31507\deff0\stshfdbch31505\stshfloch31506\stshfhich31506\stshfbi31507\deflang3079\deflangfe3079\themelang3079\themelangfe0\themelangcs0{\fonttbl{\f0\fbidi \froman\fcharset0\fprq2{*\panose 02020603050405020304}Times New Roman;}{\f0\fbidi \froman\fcharset0\fprq2{*\panose 02020603050405020304}Times New Roman;}
{\f39\fbidi \fswiss\fcharset0\fprq2{*\panose 020f0502020204030204}Calibri;}{\flomajor\f31500\fbidi \froman\fcharset0\fprq2{*\panose 02020603050405020304}Times New Roman;}
{\fdbmajor\f31501\fbidi \froman\fcharset0\fprq2{*\panose...
I wrote:
ui.Text_About->setAcceptRichText(true); QFile file("D:/Document.rtf"); file.open(QIODevice::ReadOnly | QIODevice::Text); ui.Text_About->setText(file.readAll()); file.close();
Many thanks for your help !
-
Hi
You should use
http://doc.qt.io/qt-5/qtextedit.html#html-prop
and look as the format it supports
http://doc.qt.io/qt-5/richtext-html-subset.htmlI do not think it accept rich text as in RTF text, only html.
So when docs says rich text it means text with formatting and NOT the rtf format. -
I already used html to change size, ... and it perfectly runs. The idea here was to use a RTF file generted by WordPad but as far I understand it is not possible.
Thanks. -
@mulfycrowh
Hi, I do not think it can parse and render traditional RTF at all.You can get a wonna-be WordPad with this example
http://doc.qt.io/qt-5/qtwidgets-richtext-textedit-example.htmlI assume using wordpad was to provide a good editor.
-
I've got another idea : writing the html sequence in a text file.
If I use ->setPlainText(), it doesn't understand html sequences
And if I use ->setText() it does understand thml sequences but without CRLF -
@mulfycrowh
Use the setHtml ? -
If I use
ui.Text_About->setAcceptRichText(true); QFile file("D:/help.txt"); file.open(QIODevice::ReadOnly | QIODevice::Text); ui.Text_About->setHtml(file.readAll()); file.close();
the sequences html are well understood but there are no more CRLF. That's a trouble ...
-
well how are you making those line feeds?
With html, \n \r dont count as far as i know.You must use <br> OR </p>
-
I just wrote it with Notepad.
Here are the very first lines:<html><b>Format Generator</b></html> <html><b>Developed by X - 09/17</b></html> <html><b>User's Manual</b></html> 1/ Select Items Input Folder This folder includes one item or several folders matching with various items.
-
Try using QTextEdit editor
Right click a textedit and select "Change HTML "
make the html there.
Then it will work.
Notepad and just pressing enter will not. -
You are right but with <br> it perfectly runs !
-
@mulfycrowh
super .
make sure to flag as solved :) -
Thank you again !