Fix icons not updating on theme switch in viewer panel

This commit is contained in:
Veronica Berglyd Olsen
2023-11-27 16:08:34 +01:00
parent ccc444f355
commit 1f9b6d7624
2 changed files with 49 additions and 4 deletions
+31 -4
View File
@@ -73,7 +73,7 @@ class GuiDocViewerPanel(QWidget):
self.outerBox.setContentsMargins(0, 0, 0, 0)
self.setLayout(self.outerBox)
self.updateTheme()
self.updateTheme(updateTabs=False)
logger.debug("Ready: GuiDocViewerPanel")
@@ -83,7 +83,7 @@ class GuiDocViewerPanel(QWidget):
# Methods
##
def updateTheme(self) -> None:
def updateTheme(self, updateTabs: bool = True) -> None:
"""Update theme elements."""
vPx = CONFIG.pxInt(4)
lPx = CONFIG.pxInt(2)
@@ -102,6 +102,11 @@ class GuiDocViewerPanel(QWidget):
self.mainTabs.setStyleSheet(styleSheet)
self.updateHandle(self._lastHandle)
if updateTabs:
self.tabBackRefs.updateTheme()
for tab in self.kwTabs.values():
tab.updateTheme()
return
def openProjectTasks(self) -> None:
@@ -237,6 +242,16 @@ class _ViewPanelBackRefs(QTreeWidget):
return
def updateTheme(self) -> None:
"""Update theme elements."""
self._editIcon = SHARED.theme.getIcon("edit")
self._viewIcon = SHARED.theme.getIcon("view")
for i in range(self.topLevelItemCount()):
if item := self.topLevelItem(i):
item.setIcon(self.C_EDIT, self._editIcon)
item.setIcon(self.C_VIEW, self._viewIcon)
return
def clearContent(self) -> None:
"""Clear the widget."""
self.clear()
@@ -332,6 +347,7 @@ class _ViewPanelKeyWords(QTreeWidget):
super().__init__(parent=parent)
self._parent = parent
self._class = itemClass
self._treeMap: dict[str, QTreeWidgetItem] = {}
iPx = SHARED.theme.baseIconSize
@@ -372,6 +388,17 @@ class _ViewPanelKeyWords(QTreeWidget):
return
def updateTheme(self) -> None:
"""Update theme elements."""
self._classIcon = SHARED.theme.getIcon(nwLabels.CLASS_ICON[self._class])
self._editIcon = SHARED.theme.getIcon("edit")
self._viewIcon = SHARED.theme.getIcon("view")
for i in range(self.topLevelItemCount()):
if item := self.topLevelItem(i):
item.setIcon(self.C_EDIT, self._editIcon)
item.setIcon(self.C_VIEW, self._viewIcon)
return
def countEntries(self) -> int:
"""Return the number of items in the list."""
return self.topLevelItemCount()
@@ -392,8 +419,8 @@ class _ViewPanelKeyWords(QTreeWidget):
iLevel = nwHeaders.H_LEVEL.get(hItem.level, 0) if nwItem.isDocumentLayout() else 5
hDec = SHARED.theme.getHeaderDecorationNarrow(iLevel)
# This can not use a get call to the dictionary as that creates
# some weird issue with Qt, so we need to do this with an if
# This can not use a get call to the dictionary as that would create an
# instance of the QTreeWidgetItem, which has some weird side effects
trItem = self._treeMap[tag] if tag in self._treeMap else QTreeWidgetItem()
trItem.setText(self.C_NAME, name)