Commit 53dc9f2
authored
Fix QTreeView item hover shift and excessive row padding (#1218)
* Fix QTreeView item hover shift and excessive row padding
Replace mixed margin/padding stylesheet with consistent padding across
all item states, and suppress Qt's focus rectangle with outline: 0.
Fixes #1217.
* Use palette(highlight) borders for hover/selection instead of overriding status colours
Replace static dimgrey/grey background on hover and selected states with
top/bottom borders using the system palette highlight colour. This keeps
the alert status colour (CRITICAL, WARNING, etc.) visible at all times
and works correctly in both dark and light themes.
Fixes #1219.
* Fix unreadable hover/selection on Windows dark mode
Explicitly set background-color and color using palette(highlight) and
palette(highlighted-text) on hover and selected states. Without this,
Windows' native style engine paints its own dark selection background
on top of the model's status colour, making text unreadable.
* Reverse-video hover/selection using each row's own status colours
Replace palette(highlight) with a custom delegate that swaps the row's
foreground and background colours on hover and selection, preserving the
alert status context (CRITICAL red, WARNING yellow, etc.) while still
providing clear visual feedback. Works across all themes and platforms.
* Use reverse-video delegate for status-aware hover and selection
Replace palette(highlight) CSS with a QStyledItemDelegate that swaps
each row's foreground and background colours on hover and selection.
A trivial CSS :hover rule is retained solely to opt Qt into per-item
hover tracking.
The delegate calls super().paint() first, then overdraws background and
text to guarantee the result is never overwritten by native OS styles
(QWindowsVistaStyle, QMacStyle) which ignore option.backgroundBrush.
Includes PyQt5/PyQt6 compatibility guards for QPalette.ColorRole and
Qt.AlignmentFlag enum access.
Tested on KDE Neon, Ubuntu 26.04 (GNOME), and Windows 11.
Fixes #1219.
* Fix delegate text shift on macOS by removing manual text drawing
Replace the post-paint overdraw approach (fillRect + drawText) with
colour swapping in initStyleOption instead. By stripping hover/selected
state flags there, super().paint() draws the item as a plain item,
letting each platform's native style handle text layout with its own
margins. Eliminates the leftward text shift on macOS caused by the
hardcoded adjusted(4, 0, -4, 0) text rect.
---------
Co-authored-by: Dino Korah <691011+codemedic@users.noreply.github.com>1 parent cfc7216 commit 53dc9f2
2 files changed
Lines changed: 69 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
| 145 | + | |
145 | 146 | | |
146 | 147 | | |
147 | 148 | | |
| |||
283 | 284 | | |
284 | 285 | | |
285 | 286 | | |
| 287 | + | |
286 | 288 | | |
287 | 289 | | |
288 | 290 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| 48 | + | |
47 | 49 | | |
48 | 50 | | |
| 51 | + | |
| 52 | + | |
49 | 53 | | |
50 | 54 | | |
51 | 55 | | |
52 | 56 | | |
53 | 57 | | |
54 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
55 | 66 | | |
56 | 67 | | |
57 | 68 | | |
58 | 69 | | |
59 | 70 | | |
60 | 71 | | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
61 | 120 | | |
62 | 121 | | |
63 | 122 | | |
| |||
142 | 201 | | |
143 | 202 | | |
144 | 203 | | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
154 | 210 | | |
155 | 211 | | |
| 212 | + | |
| 213 | + | |
156 | 214 | | |
157 | 215 | | |
158 | 216 | | |
| |||
0 commit comments