I wanted to have some hover effect over p tag inside QTextDocument.
I have tried to set QSS for QTextDocument using QTextDocument().setDefaultStyleSheet().
Here's what the result I have obtained;
Script;
from PySide2 import QtWidgets
class Test(QtWidgets.QTextBrowser):
def __init__(self):
super().__init__()
self.document().setDefaultStyleSheet(
"""
p.out{
background-color: "orange";
color: "black";
}
p.out:hover{
background-color: "yellow";
}
"""
)
self.setStyleSheet(
"""
QTextBrowser{
background-color: "black";
color: "white";
}
""")
self.setHtml(
"""
<p class='out'> Checking this </p>
"""
)
test = QtWidgets.QApplication([])
sample = Test()
sample.show()
test.exec_()
Color attribute inside qss worked but the hover doesn't work.
Is there any way of achieving hover effect over fragments of text inside document?

After Understanding, QTextDocument's structure and Syntax Highlighter. We can modify QTextBlock's Format whenever we want. I tried to change it's format using enterEvent, and restore format in leaveEvent.
we can modify box model using QTextFrame using QTextFrameFormat.