How do I customise the appearance of links in QLabels using style sheets?

前端 未结 4 2027
盖世英雄少女心
盖世英雄少女心 2021-02-12 23:24

I have a QLabel with a Qt stylesheet that sets a dark background:

QLabel {
background: black;
color: white;
}

This works fine unt

相关标签:
4条回答
  • 2021-02-12 23:45

    One way is to add style="color: whatever" or a class to the inner <span> of the link. I haven't figured out yet how to apply this to the whole application but it's a good start.

    0 讨论(0)
  • 2021-02-12 23:46

    Short answer is no. Recently I had to do this.

    1. QLabel!visited doesn't work because Qt doesn't track whether QLabel were visited or not.
    2. QLabel { color: ... } doesn't work for links. Can't find why but all I found is a suggestion to use QPallete in this case.
    0 讨论(0)
  • 2021-02-12 23:47

    I've had little success explicitly setting the QPalette -- it works if you set it for the entire application, but not if you set it in the widget. In the end though, the easiest thing for what I needed to do was use a QTextBrowser instead which supports a subset of HTML. I could then override the colour of links using a regular CSS stylesheet:

    QTextBrowser browser;
    // IMPORTANT! - set the stylesheet before the content
    browser->document()->setDefaultStyleSheet("a {color: white; }");
    browser->setText(html);
    
    0 讨论(0)
  • 2021-02-12 23:47

    You can set the color tag in the HTML to

    { color: inherit; } 
    
    0 讨论(0)
提交回复
热议问题