Details
-
Bug
-
Resolution: Out of scope
-
Not Evaluated
-
None
-
6.4.2
-
None
-
Windows 11 Dev Build
PySide6 installed by pip
Python 3.11.0
Description
I want to return the background color of the text if the selection changed.
It works. The only problem is that Qt returns black if I select white text. All other colors works. Black stays black.
Reproducer:
from PySide6.QtWidgets import QApplication, QMainWindow, QTextEdit from PySide6.QtCore import QRect import sys class MainWindow(QMainWindow): def __init__(self): super().__init__() self.text_entry = QTextEdit(self) self.text_entry.setGeometry(QRect(0, 0, 917, 670)) self.text_entry.setHtml("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n<html><head><meta name=\"qrichtext\" content=\"1\" /><meta charset=\"utf-8\" /><style type=\"text/css\">\np, li { white-space: pre-wrap; }\nhr { height: 1px; border-width: 0; }\nli.unchecked::marker { content: \"\\2610\"; }\nli.checked::marker { content: \"\\2612\"; }\n</style></head><body style=\" font-family:'Segoe UI'; font-size:9pt; font-weight:400; font-style:normal;\">\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:'MS Sans Serif'; color:#ffffff; background-color:#000000;\">I'm black</span></p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:'MS Sans Serif';\">I'm white</span></p>\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:'MS Sans Serif'; color:#6cdfff; background-color:#ff8649;\">I'm colorful</span></p></body></html>") self.text_entry.selectionChanged.connect(self.on_selection_changed) def on_selection_changed(self): print(self.text_entry.textBackgroundColor().name()) app = QApplication(sys.argv) window = MainWindow() window.show() sys.exit(app.exec())