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. How to display rich text with icon in ItemView items?
Forum Updated to NodeBB v4.3 + New Features

How to display rich text with icon in ItemView items?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 845 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.
  • A Offline
    A Offline
    ajaxcrypto
    wrote on last edited by
    #1

    I want to display formatted rich text (with full Qt-HTML support i.e. <font>, <b>, etc. as supported by QLabel) along with a leading or trailing icon inside an item in QTreeView. I have gone through many posts but could not find a guideline to implement in full generality which also requires stylesheet support i.e.
    QTreeView::item { background-color: ... ; font-family: .. } etc.

    Note: I need both the stylesheet properties provided and the individual items properties. How do I go about doing it using item delegates?

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

      Hi
      The delegate can only support a stylesheet if you use QStyle() paint functions.
      Sadly its not possible to query stylesheet properties so its not that easy to support Stylesheet also using pure QPainter.

      For the richtext, this can be used as a base.
      https://gist.github.com/niklasf/6124645

      1 Reply Last reply
      1
      • A Offline
        A Offline
        ajaxcrypto
        wrote on last edited by
        #3

        So basically there is no Qt API to extract those values from the stylesheet applied to the QTreeView? I cannot hard-code any values, because stylesheet will come from a different source, which I will not have control over (what properties are set). Does this imply I have to write my own CSS parser? Does Qt really not have a unified way of getting the style sheet properties in the paint method of item delegate?

        mrjjM 1 Reply Last reply
        0
        • A ajaxcrypto

          So basically there is no Qt API to extract those values from the stylesheet applied to the QTreeView? I cannot hard-code any values, because stylesheet will come from a different source, which I will not have control over (what properties are set). Does this imply I have to write my own CSS parser? Does Qt really not have a unified way of getting the style sheet properties in the paint method of item delegate?

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

          @ajaxcrypto
          Nope. No Api to read that.
          And while you can reuse Qt parser its not fun
          https://code.woboq.org/qt5/qtbase/src/gui/text/qcssparser.cpp.html

          But using QStyle paint function the values are used but you can still not read them or
          make logic based on them.

          1 Reply Last reply
          1
          • A Offline
            A Offline
            ajaxcrypto
            wrote on last edited by
            #5

            Thank you for the gist @mrjj . Any idea why Qt API is designed to not give access to QSS properties as an API? or why is the parser not exposed with public API? It means the entire requirement of writing the drawing logic by reconciling item properties + stylesheet becomes needlessly complicated now since Qt by default does not support rich text in items. This is quite unexpected from Qt, since it covers so much .

            mrjjM 1 Reply Last reply
            0
            • A ajaxcrypto

              Thank you for the gist @mrjj . Any idea why Qt API is designed to not give access to QSS properties as an API? or why is the parser not exposed with public API? It means the entire requirement of writing the drawing logic by reconciling item properties + stylesheet becomes needlessly complicated now since Qt by default does not support rich text in items. This is quite unexpected from Qt, since it covers so much .

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

              @ajaxcrypto
              I can't say why it was never made. Would surely make custom widget even more powerful.
              I guess the logic is that style sheet would allow to style std. items and Delegate allows for truly
              custom drawing.

              The https://doc.qt.io/qt-5/qproxystyle.html
              does allow to read/modify some of the values from stylesheet but not directly.

              So the best option would to use QStyle drawing to use as many values as possible but its not optimal.

              1 Reply Last reply
              1

              • Login

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