42 lines
1.5 KiB
Python
42 lines
1.5 KiB
Python
![]() |
from PySide6.QtGui import QColor, QBrush
|
||
|
from PySide6.QtWidgets import QTreeWidgetItem
|
||
|
from PySide6.QtCore import Qt
|
||
|
|
||
|
###############################################################################
|
||
|
# Kolory pastelowe (top-level + jaśniejsze dla dzieci) #
|
||
|
###############################################################################
|
||
|
GREEN = QColor("#d2ffd2") # ogólne
|
||
|
RED = QColor("#ffd2d2") # szczegółowe
|
||
|
BLUE = QColor("#d2d2ff") # przekrojowe
|
||
|
|
||
|
GREEN_LIGHT = QColor("#f0fff0")
|
||
|
RED_LIGHT = QColor("#ffecec")
|
||
|
BLUE_LIGHT = QColor("#f0f0ff")
|
||
|
|
||
|
def color_top_level_item(item: QTreeWidgetItem, color: QColor):
|
||
|
"""Ustawia tło w całym wierszu (kolumnach) na podany kolor."""
|
||
|
brush = QBrush(color)
|
||
|
for c in range(item.columnCount()):
|
||
|
item.setBackground(c, brush)
|
||
|
|
||
|
def color_item_by_title(item: QTreeWidgetItem):
|
||
|
"""Koloruje w zależności od kategorii najwyższego rodzica (ogólne / szczegółowe / przekrojowe)."""
|
||
|
top_parent = item
|
||
|
while top_parent.parent() is not None:
|
||
|
top_parent = top_parent.parent()
|
||
|
|
||
|
title_lower = top_parent.text(3).lower()
|
||
|
is_child = (item != top_parent)
|
||
|
|
||
|
if "wymagania ogólne" in title_lower:
|
||
|
color = GREEN_LIGHT if is_child else GREEN
|
||
|
elif "wymagana przekrojowe" in title_lower:
|
||
|
color = BLUE_LIGHT if is_child else BLUE
|
||
|
elif "wymagania szczegółowe" in title_lower:
|
||
|
color = RED_LIGHT if is_child else RED
|
||
|
else:
|
||
|
return # Brak dopasowania
|
||
|
|
||
|
color_top_level_item(item, color)
|
||
|
|