Improve hover highlight color in tree views. Fixes #2004621 [Dark Mode: Invisible arrow when hovering in Tag Browser](https://bugs.launchpad.net/calibre/+bug/2004621)

This commit is contained in:
Kovid Goyal 2023-02-03 17:46:08 +05:30
parent fed1d1b313
commit 118ba06700
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 20 additions and 14 deletions

View File

@ -445,3 +445,19 @@ class PaletteManager(QObject):
print('Detected a spontaneous palette change by Qt, reverting it', file=sys.stderr)
self.set_palette(pal)
self.on_palette_change()
def tree_view_hover_style(self):
g1, g2 = '#e7effd', '#cbdaf1'
border_size = '1px'
if self.is_dark_theme:
c = QApplication.instance().palette().color(QPalette.ColorRole.Highlight)
c = c.lighter(180)
g1 = g2 = c.name()
border_size = '0px'
return f'''
QTreeView::item:hover {{
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 {g1}, stop: 1 {g2});
border: {border_size} solid #bfcde4;
border-radius: 6px;
}}
'''

View File

@ -203,7 +203,7 @@ void CalibreStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *
QColor color = vopt->palette.color(QPalette::Normal, QPalette::Highlight);
QStyleOptionViewItem opt = QStyleOptionViewItem(*vopt);
if (is_color_dark(option->palette.color(QPalette::Window))) {
color = color.lighter(190);
color = color.lighter(180);
} else {
color = color.lighter(125);
}

View File

@ -238,13 +238,9 @@ class TagsView(QTreeView): # {{{
padding-bottom:PADex;
}
QTreeView::item:hover {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #e7effd, stop: 1 #cbdaf1);
border: 1px solid #bfcde4;
border-radius: 6px;
}
'''.replace('PAD', str(gprefs['tag_browser_item_padding'])) + (
'' if gprefs['tag_browser_old_look'] else stylish_tb))
'' if gprefs['tag_browser_old_look'] else stylish_tb) + QApplication.instance().palette_manager.tree_view_hover_style()
)
def set_look_and_feel(self, first=False):
self.set_style_sheet()

View File

@ -88,13 +88,7 @@ class TOCView(QTreeView):
padding-bottom:0.5ex;
}
QTreeView::item:hover {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #e7effd, stop: 1 #cbdaf1);
color: black;
border: 1px solid #bfcde4;
border-radius: 6px;
}
''')
''' + QApplication.instance().palette_manager.tree_view_hover_style())
def mouseMoveEvent(self, ev):
if self.indexAt(ev.pos()).isValid():