Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTextEdit
Qt 6.11 is out! See what's new in the release blog

QTextEdit

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 5 Posters 2.4k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bulgakovk
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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>

      1 Reply Last reply
      1
      • m.sueM Offline
        m.sueM Offline
        m.sue
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • Pradeep KumarP Offline
          Pradeep KumarP Offline
          Pradeep Kumar
          wrote on last edited by Pradeep Kumar
          #4

          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

          Pradeep Kumar
          Qt,QML Developer

          1 Reply Last reply
          2
          • Pradeep KumarP Offline
            Pradeep KumarP Offline
            Pradeep Kumar
            wrote on last edited by Pradeep Kumar
            #5

            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
            Qt,QML Developer

            B 1 Reply Last reply
            1
            • Pradeep KumarP Pradeep Kumar

              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;");
              
              B Offline
              B Offline
              bulgakovk
              wrote on last edited by
              #6

              @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?

              mrjjM 1 Reply Last reply
              0
              • B bulgakovk

                @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?

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

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

                B 1 Reply Last reply
                3
                • VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on last edited by
                  #8

                  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>"
                  

                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                  ~Napoleon Bonaparte

                  On a crusade to banish setIndexWidget() from the holy land of Qt

                  1 Reply Last reply
                  3
                  • mrjjM mrjj

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

                    B Offline
                    B Offline
                    bulgakovk
                    wrote on last edited by
                    #9

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

                    1 Reply Last reply
                    0
                    • Pradeep KumarP Offline
                      Pradeep KumarP Offline
                      Pradeep Kumar
                      wrote on last edited by
                      #10

                      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);
                      

                      Pradeep Kumar
                      Qt,QML Developer

                      1 Reply Last reply
                      2

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved