Search code examples
qthyperlinkstylesheetqtstylesheets

Qt stylesheet, how to set color of QPalette::Link and QPlatte::LinkVisited


I use a library which uses colors of QPalette::Link and QPalette::LinkVisited as background and border color for a widget. I would like to change these colors with stylesheet. How can I set color of Link and LinkVisited with help of stylesheet?

I have read, that qt doesn't support LinkVisited option for links. But in my case both colors are used not for link, but for some parts of the widget.

I would like to use stylesheet instead of setting color of QPalette. But it seems that it's impossible to set that colors with stylesheet. Is it true?

I want to set color for a Widget. I can use this code:
QPalette p;
p.setColor(QPalette::Link, QColor(0,255,0));
p.setColor(QPalette::LinkVisited, QColor(0, 255, 0));
pWidget->setPalette(p);

But I want to do the same with a stylesheet. For example something like this:
QWidget { link-color: green; link-visited-color: green;}


Solution

  • You can set the background-color & color attributes of your widget as follows, forget the QPallette:

    QWidget#yourWidgetName
    {
      background-color: #ccc;
      color: #1c1c1c;
    }
    

    Read the documentation A-Z, it has all the wisdom you gonna need when dealing with QT style-sheets

    Setting link-color & link-visited-color at the style-sheet level is not possible though.