0

I have QSting object:

 QString someString = "<a href='link'>some text</a>"

and QLabel object:

QLabel someLabel.

with this text:

someLabel.setText(someString);

I set property for QLabel:

someLabel.setProperty("class","someID"), 

and in CSS document set style for this label like this :

 #someID 
 { 
    // some style
 }

But style from CSS not appled to Label's text. It set default blue underlined style from css.

Question: How set style from CSS?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Nicholas
  • 147
  • 1
  • 2
  • 6
  • How did you apply the style to the label? Don’t confuse CSS (applied to HTML in text browsers and labels etc, must be defined inside the html itself, iirc) and the Qt style sheets (set via setStyleSheet). – Frank Osterfeld Aug 14 '15 at 14:27

2 Answers2

0

You could try to set the style sheet through the setStyleSheet() method.

Examples can be found here.

MathieuF
  • 3,130
  • 5
  • 31
  • 34
dhaumann
  • 1,590
  • 13
  • 25
0

The important distinction to make is that there are two completely separate styling systems that affect what a QLabel does:

  1. CSS stylesheets set on a widget via setStyleSheet() method.

    In these stylesheets, # selects on the id of the object - its name. So, you should be setting the object's name, not the class property:

    someLabel.setObjectName("someId");
    

    Then the #someId selector will apply to someLabel.

  2. CSS styling attributes applied to the rich text contents displayed by the label. These can be provided via in-line style attribute, for example <span style="font-size: 20px">FOO</span>. The <style> element in the <html> is also supported, but the external stylesheets are not supported - so the stylesheet must be within the <html>. All CSS 2.1 selectors are supported. For example,

    <html><style type="text/css">em {color: red}</style>
      <body><em>URGENT!</em></body>
    </html>
    
Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313