QTextEdit



  • Hello there.
    I'm trying to append string "\t<b>Test</b>" to QTextEdit widget. The problem is that widget renders only HTML and doesn't add tab symbol. Are there any ways to render both escape symbols and HTML tags? I really appreciate any advices.


  • Qt Champions 2016

    hi
    The editor seems to like it.

    code looks like
    <html><head/><body><p><span style=" font-size:8.25pt; font-weight:600;"> TEST</span></p></body></html>



  • Hi,
    you can use QPlainTextEdit to enter plain text instead of HTML.
    -Michael.



  • If you want in QTextEdit.

    use

    QTextEdit m_textedit = new QTextEdit;
    m_textedit->append("\t Text");

    it will append tab space and then prints text



  • And if you want to have the text bold and increase font size
    Qt have provided setStyleSheet method

    You can use it

    m_textedit->setStyleSheet("font-size:8.25pt; font-weight:600;");


  • @Pradeep-Kumar So I need to setStyleSheet for every HTML tag, and what about other tags like inserting image? Don't think that It's good solution.
    As I see QTextEdit can't work with both type of symbols, am I correct?


  • Qt Champions 2016

    @bulgakovk
    Hi
    It can work with tabs.
    Just right click a textedit and use the editor.
    You can then see the
    HTML code directly.



  • HTML has no "tab space" so it's not a limitation of Qt but of HTML itself, you can use &nbsp;&nbsp;&nbsp;&nbsp; as a mimic replacement

     "&nbsp;&nbsp;&nbsp;&nbsp;<b>Test</b>"
    


  • @VRonin
    Thanks
    I will try to solve my problem this way.



  • as specified by @VRonin
    you can use    &nbsp

    and if you want to insert image also you can use tags as well.

    QTextDocumentFragment fragment;
    fragment = QTextDocumentFragment::fromHtml("<img       src=':/new/prefix1/images/image.png'>");
    m_textedit->textCursor().insertFragment(fragment);

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.