6

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

warunanc
  • 2,221
  • 1
  • 23
  • 40
Funt
  • 399
  • 8
  • 23
  • Do you want to set colors of the QPallette or the QWidget that you need styling, in the later case you can definitely set colors for your widget through style sheet ? Need more information – warunanc Nov 16 '12 at 14:22
  • 1
    I have added more explanation. – Funt Nov 16 '12 at 14:48

3 Answers3

0

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>')
Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Asi
  • 116
  • 1
  • 9
-1

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.

tbs
  • 1
-2

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.

warunanc
  • 2,221
  • 1
  • 23
  • 40
  • Thanks! Yes, but how can I set the color of Link and LinkVisited with stylesheet? – Funt Nov 16 '12 at 14:48
  • 1
    Actually, I found a similar question: http://stackoverflow.com/questions/5497799/how-do-i-customise-the-appearance-of-links-in-qlabels-using-style-sheets[link] And the answer: "it's impossible" :) – Funt Nov 16 '12 at 15:12
  • 1
    Me too think, that is not possible – warunanc Nov 16 '12 at 17:06