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. insert text with css style into QTextEdit
QtWS25 Last Chance

insert text with css style into QTextEdit

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtexteditgridtable
8 Posts 3 Posters 4.2k Views
  • 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.
  • A Offline
    A Offline
    adamsmith
    wrote on 20 Jul 2019, 18:08 last edited by
    #1

    I want to insert a table with a visible grid (aka with border) but I can't seem to find a way to create a table AND style it. I am successful in inserting the <table> <tr> <th> html tags into my QTextEdit using textEdit->insertHtml("<table>.....</table>"); but I cannot style it with textEdit->insertHtml("<table style=\"border: 1px solid black;\">);, the styling just disappear, both in the sense that I cannot see the styling in the QTextEdit AND it disappears in the code that is written to the QTextEdit.

    tl;dl how do you insert a table in QTextEdit AND style it so that it has a border?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      adamsmith
      wrote on 21 Jul 2019, 10:25 last edited by
      #2

      I've also tried to insert a style tag at the beginning of my document by doing textEdit->setHtml("<style>table, tr, th {border: 1px solid black;}</style>" + defaultPage.readAll()); but the <style> </style> and everything in between gets removed for some reason! I can't see the style tags anywhere inside the code when I open the saved html document.

      I've also read up on how to set stylesheet (Apply stylesheet to HTML content in QTextEdit) and from my understanding, and experience, setting the stylesheet of the textEdit does not work either.

      tl;rd what I've tried:
      (1) inserting a table that is pre-styled with the style="" attribute
      (2) inserting style tags at the beginning of the html with textEdit->setHtml("<style>....</style>" + restOfDocument.readAll());
      (3) changing the stylesheet of the textEdit itself.
      (4) attempting to access something called "defaultStyleSheet" but there is no such function that exists in QTextEdit in my version for some reason.

      None of the above works.

      I am using Qt Creator 4.9.2. Based on Qt 5.13.0 (GCC 9.1.0, 64 bit). I am sure that the version of Qt of the project is 5.13.0 and I am compiling using:
      GCC 9.1.0 on a 64 bit Linux computer
      Qbs version 1.13.1
      QMake version 3.1

      1 Reply Last reply
      0
      • A Offline
        A Offline
        adamsmith
        wrote on 22 Jul 2019, 16:43 last edited by
        #3

        Update
        I've managed to insert a table using QTextTable but I also want to be able to insert p tags, h tags, etc. with style applied.

        R 1 Reply Last reply 3 Sept 2019, 15:39
        0
        • A adamsmith
          22 Jul 2019, 16:43

          Update
          I've managed to insert a table using QTextTable but I also want to be able to insert p tags, h tags, etc. with style applied.

          R Offline
          R Offline
          Robert Hairgrove
          wrote on 3 Sept 2019, 15:39 last edited by
          #4

          @adamsmith : I'm trying to get this to work, too, without success so far. QTextEdit just ignores the border, unlike QTableView.

          There is a list of supported CSS styles somewhere in the Qt docs, but I couldn't find any reference to the border style. It is strange if it isn't supported because border was already in CSS level 1, and it is such a basic property.

          This probably has no bearing on the problem, but the CSS reference says that if border-style is not specified, then the border will be invisible. But something like your example (border: 1px solid black;) should work with no problem.

          1 Reply Last reply
          0
          • R Offline
            R Offline
            Robert Hairgrove
            wrote on 3 Sept 2019, 15:49 last edited by
            #5

            I did find a reference to border-color and border-style, but setting these still has no effect in a QTextEdit (AFAICT).

            1 Reply Last reply
            0
            • R Offline
              R Offline
              Robert Hairgrove
              wrote on 3 Sept 2019, 17:17 last edited by
              #6

              SOLVED (???): QTextEdit will recognize the old-style HTML table border attribute, i.e.:

              <table border="1">
              

              However, it doesn't seem to honor CSS properties border-style or border-collapse.

              I suppose we'll just have to live with this, unless someone else can suggest a better way?.

              J 1 Reply Last reply 3 Sept 2019, 20:48
              0
              • R Robert Hairgrove
                3 Sept 2019, 17:17

                SOLVED (???): QTextEdit will recognize the old-style HTML table border attribute, i.e.:

                <table border="1">
                

                However, it doesn't seem to honor CSS properties border-style or border-collapse.

                I suppose we'll just have to live with this, unless someone else can suggest a better way?.

                J Offline
                J Offline
                JonB
                wrote on 3 Sept 2019, 20:48 last edited by JonB 9 Mar 2019, 20:48
                #7

                @robert-hairgrove
                https://doc.qt.io/qt-5/richtext-html-subset.html# seems to cover what you have mentioned it does and does not support?

                R 1 Reply Last reply 3 Sept 2019, 21:34
                2
                • J JonB
                  3 Sept 2019, 20:48

                  @robert-hairgrove
                  https://doc.qt.io/qt-5/richtext-html-subset.html# seems to cover what you have mentioned it does and does not support?

                  R Offline
                  R Offline
                  Robert Hairgrove
                  wrote on 3 Sept 2019, 21:34 last edited by
                  #8

                  @jonb Yes, that is the document to which I was referring. Thank you for posting the link!

                  1 Reply Last reply
                  0

                  • Login

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