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. [solved] Applying stylesheets to HTML tags in QLabel
Forum Updated to NodeBB v4.3 + New Features

[solved] Applying stylesheets to HTML tags in QLabel

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 5.3k Views 1 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.
  • K Offline
    K Offline
    kottkungen
    wrote on last edited by
    #1

    This is probably a really simple question, but I have not found any text describing this.

    I have the following piece of code:

    @
    QLabel *label = new QLabel("<h1>Header</h1><p>some text</p>");
    @

    Is it possible to apply a stylesheet to the h1-tag? I've tried

    @
    QLabel::h1 {
    color: #123456;
    }
    @

    But this does not work.

    What is the best way to apply stylesheets to parts of the text inside a QLabel?

    I might add that I'm not that experienced in stylesheets, I mostly do embedded programming.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      No, style sheets are not supported here. Qt supports a "very limited subset":/doc/qt-4.8/richtext-html-subset.html of HTML outside of the actual webkit classes. -Style sheets are not part of that.- Styles sheets are only supported in a very limited way.

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kottkungen
        wrote on last edited by
        #3

        OK, then I'll solve it some other way.

        Thanks :)

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          qxoz
          wrote on last edited by
          #4

          As Andre says "Qt supports a very limited subset of HTML outside of the actual webkit classes." But you can stil add simple styles in QLabel's html:
          @QLabel *label = new QLabel("<h1 style = color:red >Header</h1><p>some text</p>");@

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kottkungen
            wrote on last edited by
            #5

            That was actually my first solution, but I wanted to place as much of the style-setting in the CSS file. I think I'll split the information into several QLabels instead, and control each label with the stylesheet.

            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