This commit is contained in:
恍兮惚兮 2024-06-10 01:07:46 +08:00
parent 7f9b4c657e
commit 1294f4fee5
8 changed files with 31 additions and 13 deletions

View File

@ -3,7 +3,7 @@ import functools
from myutils.utils import checkencoding from myutils.utils import checkencoding
from myutils.config import globalconfig, _TR, _TRL from myutils.config import globalconfig, _TR, _TRL
from myutils.wrapper import Singleton from myutils.wrapper import Singleton
from gui.usefulwidget import getspinbox, threebuttons, getlineedit from gui.usefulwidget import getspinbox, threebuttons, getlineedit, FocusCombo
nowsuppertcodes = _TRL( nowsuppertcodes = _TRL(
[ [
@ -62,7 +62,7 @@ class codeacceptdialog(QDialog):
itemsaver = QStandardItem() itemsaver = QStandardItem()
self.model.setItem(row, 0, itemsaver) self.model.setItem(row, 0, itemsaver)
index = self.model.index(row, 0) index = self.model.index(row, 0)
codecombox = QComboBox() codecombox = FocusCombo()
codecombox.addItems((nowsuppertcodes)) codecombox.addItems((nowsuppertcodes))
codecombox.setCurrentIndex(idx) codecombox.setCurrentIndex(idx)
self.table.setIndexWidget(index, codecombox) self.table.setIndexWidget(index, codecombox)
@ -109,7 +109,7 @@ class codeacceptdialog(QDialog):
def clicked1(self): def clicked1(self):
itemsaver = QStandardItem() itemsaver = QStandardItem()
self.model.insertRow(0, [itemsaver]) self.model.insertRow(0, [itemsaver])
codecombox = QComboBox() codecombox = FocusCombo()
codecombox.addItems((nowsuppertcodes)) codecombox.addItems((nowsuppertcodes))
self._setcode_i(codecombox, itemsaver) self._setcode_i(codecombox, itemsaver)
codecombox.currentIndexChanged.connect( codecombox.currentIndexChanged.connect(

View File

@ -40,6 +40,7 @@ from gui.specialwidget import (
) )
from gui.usefulwidget import ( from gui.usefulwidget import (
yuitsu_switch, yuitsu_switch,
FocusCombo,
saveposwindow, saveposwindow,
getsimplepatheditor, getsimplepatheditor,
getboxlayout, getboxlayout,
@ -322,7 +323,7 @@ class TagWidget(QWidget):
self.setLayout(layout) self.setLayout(layout)
self.lineEdit = QComboBox() self.lineEdit = FocusCombo()
self.lineEdit.setLineEdit(QLineEdit()) self.lineEdit.setLineEdit(QLineEdit())
self.lineEdit.lineEdit().returnPressed.connect( self.lineEdit.lineEdit().returnPressed.connect(

View File

@ -12,7 +12,8 @@ from gui.usefulwidget import (
listediterline, listediterline,
getsimplepatheditor, getsimplepatheditor,
FocusSpin, FocusSpin,
FocusDoubleSpin FocusDoubleSpin,
FocusCombo
) )
@ -228,7 +229,7 @@ class autoinitdialog(QDialog):
lineW = QHBoxLayout() lineW = QHBoxLayout()
lineW.addWidget(e) lineW.addWidget(e)
elif line["type"] == "combo": elif line["type"] == "combo":
lineW = QComboBox() lineW = FocusCombo()
if "list_function" in line: if "list_function" in line:
try: try:
func = getattr( func = getattr(

View File

@ -3,7 +3,7 @@ import sqlite3, os, json, functools
from traceback import print_exc from traceback import print_exc
from myutils.config import globalconfig, _TR from myutils.config import globalconfig, _TR
from myutils.utils import autosql from myutils.utils import autosql
from gui.usefulwidget import getQMessageBox from gui.usefulwidget import getQMessageBox, FocusCombo
def sqlite2json2(self, sqlitefile, targetjson=None, existsmerge=False): def sqlite2json2(self, sqlitefile, targetjson=None, existsmerge=False):
@ -47,7 +47,7 @@ def sqlite2json2(self, sqlitefile, targetjson=None, existsmerge=False):
formLayout = QFormLayout(dialog) # 配置layout formLayout = QFormLayout(dialog) # 配置layout
dialog.setLayout(formLayout) dialog.setLayout(formLayout)
combo = QComboBox() combo = FocusCombo()
combo.addItems([globalconfig["fanyi"][_]["name"] for _ in collect]) combo.addItems([globalconfig["fanyi"][_]["name"] for _ in collect])
formLayout.addRow(_TR("首选翻译"), combo) formLayout.addRow(_TR("首选翻译"), combo)

View File

@ -13,7 +13,8 @@ from gui.usefulwidget import (
getsimplecombobox, getsimplecombobox,
getsimpleswitch, getsimpleswitch,
textbrowappendandmovetoend, textbrowappendandmovetoend,
FocusSpin FocusSpin,
FocusCombo
) )
@ -263,7 +264,7 @@ class searchhookparam(QDialog):
if len(_list) == 0: if len(_list) == 0:
regwid = addwid = line regwid = addwid = line
else: else:
combo = QComboBox() combo = FocusCombo()
combo.addItems(_list) combo.addItems(_list)
combo.setLineEdit(line) combo.setLineEdit(line)

View File

@ -25,6 +25,7 @@ from gui.usefulwidget import (
D_getsimpleswitch, D_getsimpleswitch,
makesubtab_lazy, makesubtab_lazy,
makescrollgrid, makescrollgrid,
FocusCombo
) )
@ -211,7 +212,7 @@ def getunknowgameexe(self):
formLayout = QFormLayout(dialog) formLayout = QFormLayout(dialog)
dialog.setLayout(formLayout) dialog.setLayout(formLayout)
combo = QComboBox() combo = FocusCombo()
combo.addItems([savehook_new_data[_]["title"] for _ in savehook_new_list]) combo.addItems([savehook_new_data[_]["title"] for _ in savehook_new_list])
formLayout.addRow(_TR("选择游戏"), combo) formLayout.addRow(_TR("选择游戏"), combo)

View File

@ -9,6 +9,7 @@ from gui.usefulwidget import (
makescrollgrid, makescrollgrid,
D_getcolorbutton, D_getcolorbutton,
yuitsu_switch, yuitsu_switch,
FocusCombo,
D_getsimpleswitch, D_getsimpleswitch,
) )
@ -34,7 +35,7 @@ def changevoice(self, text):
def createvoicecombo(self): def createvoicecombo(self):
self.voicecombo = QComboBox() self.voicecombo = FocusCombo()
self.voicecombo.currentTextChanged.connect(lambda x: changevoice(self, x)) self.voicecombo.currentTextChanged.connect(lambda x: changevoice(self, x))
try: try:
vl, idx = self.voicecombo_cache vl, idx = self.voicecombo_cache

View File

@ -12,6 +12,19 @@ from myutils.config import _TR, globalconfig
from myutils.wrapper import Singleton, Singleton_close from myutils.wrapper import Singleton, Singleton_close
class FocusCombo(QComboBox):
def __init__(self, parent: QWidget = None) -> None:
super().__init__(parent)
self.setFocusPolicy(Qt.FocusPolicy.StrongFocus)
def wheelEvent(self, e: QWheelEvent) -> None:
if not self.hasFocus():
e.ignore()
return
else:
return super().wheelEvent(e)
class FocusSpin(QSpinBox): class FocusSpin(QSpinBox):
def __init__(self, parent: QWidget = None) -> None: def __init__(self, parent: QWidget = None) -> None:
super().__init__(parent) super().__init__(parent)
@ -412,7 +425,7 @@ def comboboxcallbackwrap(internallist, d, k, call, _):
def getsimplecombobox(lst, d, k, callback=None, fixedsize=False, internallist=None): def getsimplecombobox(lst, d, k, callback=None, fixedsize=False, internallist=None):
s = QComboBox() s = FocusCombo()
s.addItems(lst) s.addItems(lst)
if internallist: if internallist: