Question

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;}

Was it helpful?

Solution 3

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.

OTHER TIPS

Same as you I could not found a proper way of doing that using the stylesheet or QPalette.

But for my needs to control the color I used this method, of setting <span> inside of the <a> to control to color.

QLabel().setText('<a href="..link"><span style="color:white;">something</span>')

It's the wrong place to set it. Links are a part of the document, not of the browser and QWidgets are more or less browsers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top