Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

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

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

label.setOpenExternalLinks(True)

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

# None of these work

label.setStyleSheet("color: #ffffff")

label.setStyleSheet("a{color: #ffffff}")

label.setStyleSheet("QUrl{color: #ffffff}")

1 Answer

0 votes
by (36.8k points)

If you want to change a 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())

)

 Want to be a master in Data Science? Enroll in this Data Science Courses

Browse Categories

...