Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加自定义侧边导航栏字体颜色的支持(#826) #830

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions qfluentwidgets/components/navigation/navigation_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def __init__(self, isSelectable: bool, parent=None):
self.treeParent = None
self.nodeDepth = 0
self.setFixedSize(40, 36)
# Custom font color
self._light_mode_color = QColor(0, 0, 0)
self._dark_mode_color = QColor(255, 255, 255)


def enterEvent(self, e):
self.isEnter = True
Expand Down Expand Up @@ -84,7 +88,24 @@ def setSelected(self, isSelected: bool):
self.isSelected = isSelected
self.update()
self.selectedChanged.emit(isSelected)

# About custom font color, default behavior
def getLightColor(self) -> QColor:
return self._light_mode_color

def getDarkColor(self) -> QColor:
return self._dark_mode_color

def setLightColor(self, c: QColor):
self._light_mode_color = c
self.update()

def setDarkColor(self, c: QColor):
self._dark_mode_color = c
self.update()

lightColor = pyqtProperty(QColor, getLightColor, setLightColor, user=True)
darkColor = pyqtProperty(QColor, getDarkColor, setDarkColor, user=True)

class NavigationPushButton(NavigationWidget):
""" Navigation push button """
Expand Down Expand Up @@ -161,7 +182,7 @@ def paintEvent(self, e):
return

painter.setFont(self.font())
painter.setPen(QColor(c, c, c))
painter.setPen(self._dark_mode_color if isDarkTheme() else self._light_mode_color)

left = 44 + pl if not self.icon().isNull() else pl + 16
painter.drawText(QRectF(left, 0, self.width()-13-left-pr, self.height()), Qt.AlignVCenter, self.text())
Expand Down Expand Up @@ -468,13 +489,32 @@ def _onClicked(self, triggerByUser, clickArrow):
if not clickArrow or self.isCompacted:
self.clicked.emit(triggerByUser)

def getLightColor(self) -> QColor:
return self.itemWidget._light_mode_color

def getDarkColor(self) -> QColor:
return self.itemWidget._dark_mode_color

def setLightColor(self, c: QColor):
self.itemWidget._light_mode_color = c
self.update()

def setDarkColor(self, c: QColor):
self.itemWidget._dark_mode_color = c
self.update()

lightColor = pyqtProperty(QColor, getLightColor, setLightColor, user=True)
darkColor = pyqtProperty(QColor, getDarkColor, setDarkColor, user=True)


class NavigationAvatarWidget(NavigationWidget):
""" Avatar widget """

def __init__(self, name: str, avatar: Union[str, QPixmap, QImage], parent=None):
super().__init__(isSelectable=False, parent=parent)
self.name = name
self._light_mode_color = QColor(0, 0, 0)
self._dark_mode_color = QColor(255, 255, 255)
self.setAvatar(avatar)
setFont(self)

Expand Down Expand Up @@ -513,7 +553,7 @@ def paintEvent(self, e):
painter.translate(-8, -6)

if not self.isCompacted:
painter.setPen(Qt.white if isDarkTheme() else Qt.black)
painter.setPen(self._dark_mode_color if isDarkTheme() else self._light_mode_color)
painter.setFont(self.font())
painter.drawText(QRect(44, 0, 255, 36), Qt.AlignVCenter, self.name)

Expand Down