This commit is contained in:
恍兮惚兮 2024-08-01 17:19:53 +08:00
parent cc0f5a59a4
commit 9028f7fbaa
5 changed files with 52 additions and 25 deletions

View File

@ -5,6 +5,7 @@ from qtsymbols import *
class LLabel(QLabel): class LLabel(QLabel):
def __init__(self, *argc): def __init__(self, *argc):
self.__s = None self.__s = None
self._ToolTip = None
if len(argc) == 1: if len(argc) == 1:
if isinstance(argc[0], str): if isinstance(argc[0], str):
self.__s = argc[0] self.__s = argc[0]
@ -21,6 +22,12 @@ class LLabel(QLabel):
def updatelangtext(self): def updatelangtext(self):
if self.__s: if self.__s:
super().setText(_TR(self.__s)) super().setText(_TR(self.__s))
if self._ToolTip:
super().setToolTip(_TR(self._ToolTip))
def setToolTip(self, t):
self._ToolTip = t
super().setToolTip(_TR(t))
class LMessageBox(QMessageBox): class LMessageBox(QMessageBox):

View File

@ -635,7 +635,7 @@ class CustomTabBar(LTabBar):
class QLineEdit1(QLineEdit): class QLineEdit1(QLineEdit):
def mousePressEvent(self, a0: qtawesome.QMouseEvent) -> None: def mousePressEvent(self, a0: QMouseEvent) -> None:
# 点击浏览器后,无法重新获取焦点。 # 点击浏览器后,无法重新获取焦点。
windows.SetFocus(int(self.winId())) windows.SetFocus(int(self.winId()))
return super().mousePressEvent(a0) return super().mousePressEvent(a0)

View File

@ -18,7 +18,7 @@ from gui.setting_about import doupdate
from gui.dialog_memory import dialog_memory from gui.dialog_memory import dialog_memory
from gui.textbrowser import Textbrowser from gui.textbrowser import Textbrowser
from gui.rangeselect import rangeselct_function from gui.rangeselect import rangeselct_function
from gui.usefulwidget import resizableframeless, isinrect, getQMessageBox from gui.usefulwidget import resizableframeless, isinrect, getQMessageBox, LIconLabel
from gui.edittext import edittrans from gui.edittext import edittrans
from gui.dialog_savedgame import browserdialog, dialog_savedgame_integrated from gui.dialog_savedgame import browserdialog, dialog_savedgame_integrated
from gui.dynalang import LPushButton, LDialog from gui.dynalang import LPushButton, LDialog
@ -1035,26 +1035,8 @@ class QUnFrameWindow(resizableframeless):
button.clicked.connect(functools.partial(self.callwrap, clickfunc)) button.clicked.connect(functools.partial(self.callwrap, clickfunc))
else: else:
class __(LPushButton):
def __init__(self, p):
super().__init__(p)
self._lb = QLabel(p)
self._lb.setStyleSheet("background-color: transparent;")
self._lb.raise_()
def hideEvent(self, _): button = LIconLabel(self._TitleLabel)
self._lb.hide()
def showEvent(self, _):
self._lb.show()
def moveEvent(self, event):
self._lb.move(event.pos())
def resizeEvent(self, event):
self._lb.resize(event.size())
button = __(self._TitleLabel)
if tips: if tips:
button.setToolTip(tips) button.setToolTip(tips)

View File

@ -1928,3 +1928,39 @@ class statusbutton(QPushButton):
def setEnabled(self, _): def setEnabled(self, _):
super().setEnabled(_) super().setEnabled(_)
self.seticon() self.seticon()
class LIconLabel(LLabel):
def __init__(self, *argc):
super().__init__(*argc)
self._icon = QIcon()
self._size = QSize()
def setIcon(self, icon: QIcon):
self._icon = icon
self.update()
def setIconSize(self, size: QSize):
self._size = size
self.update()
def paintEvent(self, a0: QPaintEvent) -> None:
painter = QPainter(self)
if self._size.isEmpty():
size = self.size()
else:
size = self._size
rect = QRect(
(self.width() - size.width()) // 2,
(self.height() - size.height()) // 2,
size.width(),
size.height(),
)
self._icon.paint(
painter,
rect,
Qt.AlignmentFlag.AlignCenter,
QIcon.Mode.Normal,
QIcon.State.On,
)

View File

@ -5,7 +5,7 @@ from qtsymbols import *
class CharIconPainter: class CharIconPainter:
def paint(self, iconic, painter, rect, char, color): def paint(self, iconic, painter, rect, mode, state, char, color):
painter.save() painter.save()
qcolor = QColor(color) qcolor = QColor(color)
painter.setPen(qcolor) painter.setPen(qcolor)
@ -28,13 +28,15 @@ class CharIconEngine(QIconEngine):
self.char = char self.char = char
self.color = color self.color = color
def paint(self, painter, rect): def paint(self, painter, rect, mode, state):
self.painter.paint(self.iconic, painter, rect, self.char, self.color) self.painter.paint(
self.iconic, painter, rect, mode, state, self.char, self.color
)
def pixmap(self, size, mode, state): def pixmap(self, size, mode, state):
pm = QPixmap(size) pm = QPixmap(size)
pm.fill(Qt.GlobalColor.transparent) pm.fill(Qt.GlobalColor.transparent)
self.paint(QPainter(pm), QRect(QPoint(0, 0), size)) self.paint(QPainter(pm), QRect(QPoint(0, 0), size), mode, state)
return pm return pm