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):
def __init__(self, *argc):
self.__s = None
self._ToolTip = None
if len(argc) == 1:
if isinstance(argc[0], str):
self.__s = argc[0]
@ -21,6 +22,12 @@ class LLabel(QLabel):
def updatelangtext(self):
if 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):

View File

@ -635,7 +635,7 @@ class CustomTabBar(LTabBar):
class QLineEdit1(QLineEdit):
def mousePressEvent(self, a0: qtawesome.QMouseEvent) -> None:
def mousePressEvent(self, a0: QMouseEvent) -> None:
# 点击浏览器后,无法重新获取焦点。
windows.SetFocus(int(self.winId()))
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.textbrowser import Textbrowser
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.dialog_savedgame import browserdialog, dialog_savedgame_integrated
from gui.dynalang import LPushButton, LDialog
@ -1035,26 +1035,8 @@ class QUnFrameWindow(resizableframeless):
button.clicked.connect(functools.partial(self.callwrap, clickfunc))
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, _):
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)
button = LIconLabel(self._TitleLabel)
if tips:
button.setToolTip(tips)

View File

@ -1928,3 +1928,39 @@ class statusbutton(QPushButton):
def setEnabled(self, _):
super().setEnabled(_)
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:
def paint(self, iconic, painter, rect, char, color):
def paint(self, iconic, painter, rect, mode, state, char, color):
painter.save()
qcolor = QColor(color)
painter.setPen(qcolor)
@ -28,13 +28,15 @@ class CharIconEngine(QIconEngine):
self.char = char
self.color = color
def paint(self, painter, rect):
self.painter.paint(self.iconic, painter, rect, self.char, self.color)
def paint(self, painter, rect, mode, state):
self.painter.paint(
self.iconic, painter, rect, mode, state, self.char, self.color
)
def pixmap(self, size, mode, state):
pm = QPixmap(size)
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