CasualDemon
CasualDemon

Reputation: 6160

How do I change the color of an external link?

I have a label with an eternal link in it, that I would like to change the color from the default blue to white.

label = QtWidgets.QLabel("<a href='https://example.com'> My Link </a>")
label.setOpenExternalLinks(True)

I have tried three different methods and have found no further documentation to point me in the right direction, any guidance would be appreciated:

# None of these work
label.setStyleSheet("color: #ffffff")
label.setStyleSheet("a{color: #ffffff}")
label.setStyleSheet("QUrl{color: #ffffff}")

Upvotes: 1

Views: 679

Answers (1)

eyllanesc
eyllanesc

Reputation: 244202

If you want to change the color you must use the style within the HTML:

color = QtGui.QColor("white")
label = QtWidgets.QLabel(
    "<a href='https://example.com' style='color:{}'> My Link </a>".format(color.name())
)

Upvotes: 3

Related Questions