diff --git a/LunaTranslator/LunaTranslator/gui/codeacceptdialog.py b/LunaTranslator/LunaTranslator/gui/codeacceptdialog.py index 84dd4c91..75f83da6 100644 --- a/LunaTranslator/LunaTranslator/gui/codeacceptdialog.py +++ b/LunaTranslator/LunaTranslator/gui/codeacceptdialog.py @@ -3,7 +3,7 @@ import functools from myutils.utils import checkencoding from myutils.config import globalconfig, _TR, _TRL from myutils.wrapper import Singleton -from gui.usefulwidget import getspinbox, threebuttons, getlineedit +from gui.usefulwidget import getspinbox, threebuttons, getlineedit, FocusCombo nowsuppertcodes = _TRL( [ @@ -62,7 +62,7 @@ class codeacceptdialog(QDialog): itemsaver = QStandardItem() self.model.setItem(row, 0, itemsaver) index = self.model.index(row, 0) - codecombox = QComboBox() + codecombox = FocusCombo() codecombox.addItems((nowsuppertcodes)) codecombox.setCurrentIndex(idx) self.table.setIndexWidget(index, codecombox) @@ -109,7 +109,7 @@ class codeacceptdialog(QDialog): def clicked1(self): itemsaver = QStandardItem() self.model.insertRow(0, [itemsaver]) - codecombox = QComboBox() + codecombox = FocusCombo() codecombox.addItems((nowsuppertcodes)) self._setcode_i(codecombox, itemsaver) codecombox.currentIndexChanged.connect( diff --git a/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py b/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py index 724efe70..e1b455fb 100644 --- a/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py +++ b/LunaTranslator/LunaTranslator/gui/dialog_savedgame.py @@ -40,6 +40,7 @@ from gui.specialwidget import ( ) from gui.usefulwidget import ( yuitsu_switch, + FocusCombo, saveposwindow, getsimplepatheditor, getboxlayout, @@ -322,7 +323,7 @@ class TagWidget(QWidget): self.setLayout(layout) - self.lineEdit = QComboBox() + self.lineEdit = FocusCombo() self.lineEdit.setLineEdit(QLineEdit()) self.lineEdit.lineEdit().returnPressed.connect( diff --git a/LunaTranslator/LunaTranslator/gui/inputdialog.py b/LunaTranslator/LunaTranslator/gui/inputdialog.py index fdc9193c..3b56997b 100644 --- a/LunaTranslator/LunaTranslator/gui/inputdialog.py +++ b/LunaTranslator/LunaTranslator/gui/inputdialog.py @@ -12,7 +12,8 @@ from gui.usefulwidget import ( listediterline, getsimplepatheditor, FocusSpin, - FocusDoubleSpin + FocusDoubleSpin, + FocusCombo ) @@ -228,7 +229,7 @@ class autoinitdialog(QDialog): lineW = QHBoxLayout() lineW.addWidget(e) elif line["type"] == "combo": - lineW = QComboBox() + lineW = FocusCombo() if "list_function" in line: try: func = getattr( diff --git a/LunaTranslator/LunaTranslator/gui/pretransfile.py b/LunaTranslator/LunaTranslator/gui/pretransfile.py index a438d5e1..33393d0d 100644 --- a/LunaTranslator/LunaTranslator/gui/pretransfile.py +++ b/LunaTranslator/LunaTranslator/gui/pretransfile.py @@ -3,7 +3,7 @@ import sqlite3, os, json, functools from traceback import print_exc from myutils.config import globalconfig, _TR from myutils.utils import autosql -from gui.usefulwidget import getQMessageBox +from gui.usefulwidget import getQMessageBox, FocusCombo def sqlite2json2(self, sqlitefile, targetjson=None, existsmerge=False): @@ -47,7 +47,7 @@ def sqlite2json2(self, sqlitefile, targetjson=None, existsmerge=False): formLayout = QFormLayout(dialog) # 配置layout dialog.setLayout(formLayout) - combo = QComboBox() + combo = FocusCombo() combo.addItems([globalconfig["fanyi"][_]["name"] for _ in collect]) formLayout.addRow(_TR("首选翻译"), combo) diff --git a/LunaTranslator/LunaTranslator/gui/selecthook.py b/LunaTranslator/LunaTranslator/gui/selecthook.py index 0a54fc2f..f8369528 100644 --- a/LunaTranslator/LunaTranslator/gui/selecthook.py +++ b/LunaTranslator/LunaTranslator/gui/selecthook.py @@ -13,7 +13,8 @@ from gui.usefulwidget import ( getsimplecombobox, getsimpleswitch, textbrowappendandmovetoend, - FocusSpin + FocusSpin, + FocusCombo ) @@ -263,7 +264,7 @@ class searchhookparam(QDialog): if len(_list) == 0: regwid = addwid = line else: - combo = QComboBox() + combo = FocusCombo() combo.addItems(_list) combo.setLineEdit(line) diff --git a/LunaTranslator/LunaTranslator/gui/setting_textinput.py b/LunaTranslator/LunaTranslator/gui/setting_textinput.py index 36e44ea4..d5a8eb53 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_textinput.py +++ b/LunaTranslator/LunaTranslator/gui/setting_textinput.py @@ -25,6 +25,7 @@ from gui.usefulwidget import ( D_getsimpleswitch, makesubtab_lazy, makescrollgrid, + FocusCombo ) @@ -211,7 +212,7 @@ def getunknowgameexe(self): formLayout = QFormLayout(dialog) dialog.setLayout(formLayout) - combo = QComboBox() + combo = FocusCombo() combo.addItems([savehook_new_data[_]["title"] for _ in savehook_new_list]) formLayout.addRow(_TR("选择游戏"), combo) diff --git a/LunaTranslator/LunaTranslator/gui/setting_tts.py b/LunaTranslator/LunaTranslator/gui/setting_tts.py index 19856e7c..841d07ba 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_tts.py +++ b/LunaTranslator/LunaTranslator/gui/setting_tts.py @@ -9,6 +9,7 @@ from gui.usefulwidget import ( makescrollgrid, D_getcolorbutton, yuitsu_switch, + FocusCombo, D_getsimpleswitch, ) @@ -34,7 +35,7 @@ def changevoice(self, text): def createvoicecombo(self): - self.voicecombo = QComboBox() + self.voicecombo = FocusCombo() self.voicecombo.currentTextChanged.connect(lambda x: changevoice(self, x)) try: vl, idx = self.voicecombo_cache diff --git a/LunaTranslator/LunaTranslator/gui/usefulwidget.py b/LunaTranslator/LunaTranslator/gui/usefulwidget.py index 248925dd..73829b60 100644 --- a/LunaTranslator/LunaTranslator/gui/usefulwidget.py +++ b/LunaTranslator/LunaTranslator/gui/usefulwidget.py @@ -12,6 +12,19 @@ from myutils.config import _TR, globalconfig 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): def __init__(self, parent: QWidget = None) -> None: super().__init__(parent) @@ -412,7 +425,7 @@ def comboboxcallbackwrap(internallist, d, k, call, _): def getsimplecombobox(lst, d, k, callback=None, fixedsize=False, internallist=None): - s = QComboBox() + s = FocusCombo() s.addItems(lst) if internallist: