提交 537109f3 编写于 作者: 之一Yo's avatar 之一Yo

添加直接更换 item 字体和前景色的功能

上级 0f48ed69
......@@ -33,7 +33,7 @@ class Demo(QWidget):
]
for stand in stands:
item = QListWidgetItem(stand)
# item.setIcon(QIcon('docs/source/_static/logo.png'))
# item.setIcon(QIcon(':/qfluentwidgets/images/logo.png'))
# item.setCheckState(Qt.Unchecked)
self.listWidget.addItem(item)
......
......@@ -12,7 +12,7 @@ Examples are available at https://github.com/zhiyiYo/PyQt-Fluent-Widgets/tree/ma
:license: GPLv3, see LICENSE for more details.
"""
__version__ = "0.9.2"
__version__ = "0.9.3"
from .components import *
from .common import *
......
此差异已折叠。
<RCC>
<qresource prefix="/qfluentwidgets">
<file>images/logo.png</file>
<file>images/color_dialog/Clear_black.svg</file>
<file>images/color_dialog/Clear_white.svg</file>
<file>images/color_dialog/HuePanel.png</file>
......
......@@ -5,8 +5,10 @@ from PyQt5.QtCore import Qt, pyqtSignal
from PyQt5.QtGui import QPainter, QFont
from PyQt5.QtWidgets import QApplication, QPushButton, QWidget, QHBoxLayout, QSizePolicy
from ...common.router import qrouter
from ...common.style_sheet import themeColor, FluentStyleSheet
from ..widgets.scroll_area import SingleDirectionScrollArea
from .navigation_panel import RouteKeyError
class PivotItem(QPushButton):
......@@ -71,7 +73,7 @@ class Pivot(QWidget):
self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)
def addItem(self, routeKey: str, text: str, onClick):
def addItem(self, routeKey: str, text: str, onClick=None):
""" add item
Parameters
......@@ -87,7 +89,23 @@ class Pivot(QWidget):
"""
return self.insertItem(-1, routeKey, text, onClick)
def insertItem(self, index: int, routeKey: str, text: str, onClick):
def addWidget(self, routeKey: str, widget: PivotItem, onClick=None):
""" add widget
Parameters
----------
routeKey: str
the unique name of item
widget: PivotItem
navigation widget
onClick: callable
the slot connected to item clicked signal
"""
self.insertWidget(-1, routeKey, widget, onClick)
def insertItem(self, index: int, routeKey: str, text: str, onClick=None):
""" insert item
Parameters
......@@ -108,14 +126,62 @@ class Pivot(QWidget):
return
item = PivotItem(text, self)
item.setProperty('routeKey', routeKey)
item.itemClicked.connect(self._onItemClicked)
item.itemClicked.connect(onClick)
self.items[routeKey] = item
self.hBoxLayout.insertWidget(index, item, 0, Qt.AlignLeft)
self.insertWidget(index, routeKey, item, onClick)
return item
def insertWidget(self, index: int, routeKey: str, widget: PivotItem, onClick=None):
""" insert item
Parameters
----------
index: int
insert position
routeKey: str
the unique name of item
widget: PivotItem
navigation widget
onClick: callable
the slot connected to item clicked signal
"""
if routeKey in self.items:
return
widget.setProperty('routeKey', routeKey)
widget.itemClicked.connect(self._onItemClicked)
if onClick:
widget.itemClicked.connect(onClick)
self.items[routeKey] = widget
self.hBoxLayout.insertWidget(index, widget, 0, Qt.AlignLeft)
def removeWidget(self, routeKey: str):
""" remove widget
Parameters
----------
routeKey: str
the unique name of item
"""
if routeKey not in self.items:
return
item = self.items.pop(routeKey)
self.hBoxLayout.removeWidget(item)
qrouter.remove(routeKey)
item.deleteLater()
def clear(self):
""" clear all navigation items """
for k, w in self.items.items():
self.hBoxLayout.removeWidget(w)
qrouter.remove(k)
w.deleteLater()
self.items.clear()
def setCurrentItem(self, routeKey: str):
""" set current selected item
......@@ -141,3 +207,9 @@ class Pivot(QWidget):
def _onItemClicked(self):
item = self.sender() # type: PivotItem
self.setCurrentItem(item.property('routeKey'))
def widget(self, routeKey: str):
if routeKey not in self.items:
raise RouteKeyError(f"`{routeKey}` is illegal.")
return self.items[routeKey]
\ No newline at end of file
......@@ -2,9 +2,9 @@
from typing import List, Union
from PyQt5.QtCore import Qt, QMargins, QModelIndex, QItemSelectionModel
from PyQt5.QtGui import QPainter, QColor, QKeyEvent, QPalette
from PyQt5.QtGui import QPainter, QColor, QKeyEvent, QPalette, QBrush
from PyQt5.QtWidgets import (QStyledItemDelegate, QApplication, QStyleOptionViewItem,
QTableView, QTableWidget, QWidget, QTableWidgetItem)
QTableView, QTableWidget, QWidget, QTableWidgetItem, QHeaderView)
from ...common.font import getFont
from ...common.style_sheet import isDarkTheme, FluentStyleSheet, themeColor
......@@ -79,13 +79,18 @@ class TableItemDelegate(QStyledItemDelegate):
def initStyleOption(self, option: QStyleOptionViewItem, index: QModelIndex):
super().initStyleOption(option, index)
option.font = getFont(13)
if isDarkTheme():
option.palette.setColor(QPalette.Text, Qt.white)
option.palette.setColor(QPalette.HighlightedText, Qt.white)
else:
option.palette.setColor(QPalette.Text, Qt.black)
option.palette.setColor(QPalette.HighlightedText, Qt.black)
# font
option.font = index.data(Qt.FontRole) or getFont(13)
# text color
textColor = Qt.white if isDarkTheme() else Qt.black
textBrush = index.data(Qt.TextColorRole) # type: QBrush
if textBrush is not None:
textColor = textBrush.color()
option.palette.setColor(QPalette.Text, textColor)
option.palette.setColor(QPalette.HighlightedText, textColor)
def paint(self, painter, option, index):
painter.save()
......
......@@ -41,13 +41,18 @@ class TreeItemDelegate(QStyledItemDelegate):
def initStyleOption(self, option, index):
super().initStyleOption(option, index)
option.font = getFont(13)
if isDarkTheme():
option.palette.setColor(QPalette.Text, Qt.white)
option.palette.setColor(QPalette.HighlightedText, Qt.white)
else:
option.palette.setColor(QPalette.Text, Qt.black)
option.palette.setColor(QPalette.HighlightedText, Qt.black)
# font
option.font = index.data(Qt.FontRole) or getFont(13)
# text color
textColor = Qt.white if isDarkTheme() else Qt.black
textBrush = index.data(Qt.TextColorRole)
if textBrush is not None:
textColor = textBrush.color()
option.palette.setColor(QPalette.Text, textColor)
option.palette.setColor(QPalette.HighlightedText, textColor)
class TreeViewBase:
......
......@@ -6,7 +6,7 @@ with open('README.md', encoding='utf-8') as f:
setuptools.setup(
name="PyQt-Fluent-Widgets",
version="0.9.2",
version="0.9.3",
keywords="pyqt fluent widgets",
author="zhiyiYo",
author_email="shokokawaii@outlook.com",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册