I made 2 labels and linked them using html tag(<a></a>
) and make event for each of them when they are hovered. Problem is that the only working event is background-color
and attributes like color
, font-size
doesn't work
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
from PyQt5.QtWidgets import *
def first_label () :
style = """
QLabel#label:hover{
color: green;
}
"""
label.setStyleSheet(style)
def second_label (link) :
style = """
QLabel#label2:hover{
background-color: green;
}
"""
label2.setStyleSheet(style)
app = QtWidgets.QApplication(sys.argv)
window = QtWidgets.QWidget()
window.resize(472, 379)
# First QLabel---------------------------------------
label = QtWidgets.QLabel(window)
label.setGeometry(QtCore.QRect(180, 120, 111, 41))
font = QtGui.QFont()
font.setPointSize(20)
label.setFont(font)
label.setOpenExternalLinks(True)
label.setObjectName("label")
label.setText("<a style='text-decoration:none; color : black; font-size:100%;' href='#'> First </a>")
label.linkHovered.connect(first_label)
# Second QLabel---------------------------------------
label2 = QtWidgets.QLabel(window)
label2.setGeometry(QtCore.QRect(180, 120, 111, 41))
font = QtGui.QFont()
font.setPointSize(20)
label2.setFont(font)
label2.setOpenExternalLinks(True)
label2.setObjectName("label2")
label2.move(174,160)
label2.setText("<a style='text-decoration:none; color: black; font-size:100%;' href='#'> Second </a>")
label2.linkHovered.connect(second_label)
window.show()
sys.exit(app.exec_())