Я написал сложную программу, использующую таблицу PyQt6. Я столкнулся с проблемой, из-за которой мне не удалось изменить цвет шрифта в таблице. Для устранения неполадок я создал программу меньшего размера (см. ниже), которая генерирует таблицу PyQt6 из одной ячейки, содержащую букву «А» красным шрифтом. Однако после выполнения кода символ «А» остался черным. Ниже приведен код с комментариями. Мы очень ценим вашу помощь.
import sys
from PyQt6.QtWidgets import QApplication, QTableWidget, QTableWidgetItem, QMainWindow
from PyQt6.QtGui import QColor
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
# Set up the table widget
self.table = QTableWidget(1, 1)
self.table.setHorizontalHeaderLabels(["Character"])
# Create the table item with the "A" character
item = QTableWidgetItem("A")
# Set the font color of the item to red
item.setForeground(QColor('red'))
# Add the item to the table
self.table.setItem(0, 0, item)
# Set the table as the central widget of the window
self.setCentralWidget(self.table)
# Set the window title
self.setWindowTitle("Table")
# Set the window size
self.resize(300, 200)
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec())
Подробнее здесь: https://stackoverflow.com/questions/786 ... ablewidget