Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to use border-color and border-collapse in html table?
Forum Update on Monday, May 27th 2025

How to use border-color and border-collapse in html table?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
9 Posts 3 Posters 3.0k 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.
  • Q Offline
    Q Offline
    Quang Phu
    wrote on 2 Mar 2020, 07:15 last edited by Quang Phu 3 Feb 2020, 08:19
    #1

    Hi everyone,

    I want to create a simple table in html file and show it in Qt app, but it seem border-color and border-collapse don't work on qml?
    I created an example:

    import QtQuick 2.14
    import QtQuick.Window 2.14
    
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
        Rectangle {
            anchors.fill: parent
            color: "lightblue"
            Text {
                id: mytext
                anchors.centerIn: parent
                textFormat: Text.RichText
                text: "<table border=\"1\" border-collapse=\"collapse\" border-color=\"red\" width=\"300\" cellspacing=\"0\" cellpadding=\"0\"><tr><td>whaterever</td><td>whaterever</td></tr><tr><td>whaterever</td><td>whaterever</td></tr>"
            }
        }
    }
    

    but this is result:
    Screenshot from 2020-03-02 14-12-35.png
    So how can I deal with this, or are there any ways to use html table in QML?

    J 1 Reply Last reply 5 Mar 2020, 04:00
    0
    • Q Offline
      Q Offline
      Quang Phu
      wrote on 3 Mar 2020, 10:35 last edited by
      #2

      Up......

      J 1 Reply Last reply 3 Mar 2020, 13:12
      0
      • Q Quang Phu
        3 Mar 2020, 10:35

        Up......

        J Offline
        J Offline
        JonB
        wrote on 3 Mar 2020, 13:12 last edited by
        #3

        @Quang-Phu
        I admit I don't know about about border-color, but what makes you think Qt/QML tables should do anything with border-collapse? So far as I know QML/Qt Quick does not offer a full HTML interpreter.

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          Quang Phu
          wrote on 5 Mar 2020, 01:06 last edited by
          #4

          @JonB ,
          I just want to view a normal table in html file in QML (with custom color and collapse line) and waiting solution.
          In normal html these properties work well, did I miss something??

          1 Reply Last reply
          0
          • Q Quang Phu
            2 Mar 2020, 07:15

            Hi everyone,

            I want to create a simple table in html file and show it in Qt app, but it seem border-color and border-collapse don't work on qml?
            I created an example:

            import QtQuick 2.14
            import QtQuick.Window 2.14
            
            Window {
                visible: true
                width: 640
                height: 480
                title: qsTr("Hello World")
                Rectangle {
                    anchors.fill: parent
                    color: "lightblue"
                    Text {
                        id: mytext
                        anchors.centerIn: parent
                        textFormat: Text.RichText
                        text: "<table border=\"1\" border-collapse=\"collapse\" border-color=\"red\" width=\"300\" cellspacing=\"0\" cellpadding=\"0\"><tr><td>whaterever</td><td>whaterever</td></tr><tr><td>whaterever</td><td>whaterever</td></tr>"
                    }
                }
            }
            

            but this is result:
            Screenshot from 2020-03-02 14-12-35.png
            So how can I deal with this, or are there any ways to use html table in QML?

            J Offline
            J Offline
            JKSH
            Moderators
            wrote on 5 Mar 2020, 04:00 last edited by JKSH 3 May 2020, 14:15
            #5

            @Quang-Phu said in How to use border-color and border-collapse in html table?:

            it seem border-color and border-collapse don't work on qml?

            The documentation (https://doc.qt.io/qt-5/qml-qtquick-text.html ) says, "Note that the Supported HTML Subset is limited." The supported tags are listed at https://doc.qt.io/qt-5/richtext-html-subset. border-color and border-collapse are not supported.

            EDIT: border-color and border-collapse are supported in Qt, but they are CSS properties, not HTML attributes. They must be placed in a stylesheet or the style attribute.

            If you want a full-fledged HTML renderer, you must use a web engine like https://doc.qt.io/qt-5/qml-qtwebengine-webengineview.html

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            J 1 Reply Last reply 5 Mar 2020, 08:27
            4
            • Q Offline
              Q Offline
              Quang Phu
              wrote on 5 Mar 2020, 05:49 last edited by Quang Phu 3 May 2020, 05:51
              #6

              @JKSH got it.
              I am trying to use WebView instead, It looks good in desktop app. But I want to view a html file in my app Resources on android device.
              I created an example for android, it shows an error: Webpage not available. How can I deal with this??
              Screenshot from 2020-03-05 12-48-56.png

              This is sample code:

              import QtQuick 2.14
              import QtQuick.Window 2.14
              import QtWebView 1.0
              
              Window {
                  visible: true
                  width: 640
                  height: 480
                  title: qsTr("Hello World")
                  Rectangle {
                      anchors.fill: parent
                      color: "lightblue"
                      WebView {
                          anchors.fill: parent
                          url: ":/AAnThe.html"
                      }
                  }
              }
              
              
              1 Reply Last reply
              0
              • J JKSH
                5 Mar 2020, 04:00

                @Quang-Phu said in How to use border-color and border-collapse in html table?:

                it seem border-color and border-collapse don't work on qml?

                The documentation (https://doc.qt.io/qt-5/qml-qtquick-text.html ) says, "Note that the Supported HTML Subset is limited." The supported tags are listed at https://doc.qt.io/qt-5/richtext-html-subset. border-color and border-collapse are not supported.

                EDIT: border-color and border-collapse are supported in Qt, but they are CSS properties, not HTML attributes. They must be placed in a stylesheet or the style attribute.

                If you want a full-fledged HTML renderer, you must use a web engine like https://doc.qt.io/qt-5/qml-qtwebengine-webengineview.html

                J Offline
                J Offline
                JonB
                wrote on 5 Mar 2020, 08:27 last edited by
                #7

                @JKSH said in How to use border-color and border-collapse in html table?:

                The supported tags are listed at https://doc.qt.io/qt-5/richtext-html-subset. border-color and border-collapse are not supported.

                https://doc.qt.io/qt-5/richtext-html-subset.html#css-properties :

                border-collapse collapse | separate Border Collapse mode for text tables. If set to collapse, cell-spacing will not be applied.
                border-color <color> Border color for text tables and table cells.

                J 1 Reply Last reply 5 Mar 2020, 14:12
                3
                • J JonB
                  5 Mar 2020, 08:27

                  @JKSH said in How to use border-color and border-collapse in html table?:

                  The supported tags are listed at https://doc.qt.io/qt-5/richtext-html-subset. border-color and border-collapse are not supported.

                  https://doc.qt.io/qt-5/richtext-html-subset.html#css-properties :

                  border-collapse collapse | separate Border Collapse mode for text tables. If set to collapse, cell-spacing will not be applied.
                  border-color <color> Border color for text tables and table cells.

                  J Offline
                  J Offline
                  JKSH
                  Moderators
                  wrote on 5 Mar 2020, 14:12 last edited by JKSH 3 Jun 2020, 02:17
                  #8

                  @JonB said in How to use border-color and border-collapse in html table?:

                  @JKSH said in How to use border-color and border-collapse in html table?:

                  The supported tags are listed at https://doc.qt.io/qt-5/richtext-html-subset. border-color and border-collapse are not supported.

                  https://doc.qt.io/qt-5/richtext-html-subset.html#css-properties :

                  border-collapse collapse | separate Border Collapse mode for text tables. If set to collapse, cell-spacing will not be applied.
                  border-color <color> Border color for text tables and table cells.

                  Well, that's very embarrassing. Whoops!

                  Anyway, the problem is invalid HTML code. If you put the original code in a .html file, a web browser won't render it correctly either. border-collapse and border-color are CSS properties, not HTML attributes.

                  • Wrong: <table border-color="red">
                  • Correct: <table style="border-color:red">

                  Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                  J 1 Reply Last reply 5 Mar 2020, 18:23
                  3
                  • J JKSH
                    5 Mar 2020, 14:12

                    @JonB said in How to use border-color and border-collapse in html table?:

                    @JKSH said in How to use border-color and border-collapse in html table?:

                    The supported tags are listed at https://doc.qt.io/qt-5/richtext-html-subset. border-color and border-collapse are not supported.

                    https://doc.qt.io/qt-5/richtext-html-subset.html#css-properties :

                    border-collapse collapse | separate Border Collapse mode for text tables. If set to collapse, cell-spacing will not be applied.
                    border-color <color> Border color for text tables and table cells.

                    Well, that's very embarrassing. Whoops!

                    Anyway, the problem is invalid HTML code. If you put the original code in a .html file, a web browser won't render it correctly either. border-collapse and border-color are CSS properties, not HTML attributes.

                    • Wrong: <table border-color="red">
                    • Correct: <table style="border-color:red">
                    J Offline
                    J Offline
                    JonB
                    wrote on 5 Mar 2020, 18:23 last edited by
                    #9

                    @JKSH Damn good point :) Couldn't see the wood for the trees....

                    1 Reply Last reply
                    0

                    1/9

                    2 Mar 2020, 07:15

                    • Login

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