44from ui .uiComponents import RoundQDialog
55from country_name import country_name
66from PyQt5 .QtGui import QPixmap
7+ from PyQt5 .QtCore import Qt
78
89class ui_Form (Ui_Form ):
910 def __init__ (self , mainWindow ):
@@ -37,19 +38,16 @@ def __init__(self, mainWindow):
3738
3839 self .Dialog = RoundQDialog (mainWindow .mainWindow )
3940 self .setupUi (self .Dialog )
40- self .setParameter ()
4141 self .Dialog .setWindowIcon (QtGui .QIcon (str (self .r_path .with_name ('media' ).joinpath ('cat.ico' ))))
42+
4243 self .pushButton_yes .clicked .connect (self .processParameter )
4344 self .pushButton_no .clicked .connect (self .Dialog .close )
44- self .comboBox_country .resize .connect (self .set_lineedit_country_geometry )
45- self .lineEdit_country .textEdited .connect (lambda x : self .set_combobox_country (x ))
46- self .comboBox_country .activated ['QString' ].connect (lambda x : self .set_country_flag (x ))
47- self .lineEdit_country .textEdited .connect (lambda x : self .set_country_flag (x ))
48-
45+ # self.comboBox_country.activated['QString'].connect(lambda x: self.onchange_combobox_country(x))
46+ self .comboBox_country .editTextChanged .connect (self .onchange_combobox_country )
47+ self .comboBox_country .lineEdit ().setAlignment (Qt .AlignCenter )
4948 self .country_name = list (country_name .keys ())
50- self .set_combobox_country (self .lineEdit_country .text ())
51- self .set_country_flag (self .lineEdit_country .text ())
52-
49+ self .setParameter ()
50+
5351 def set_country_flag (self , flag_name ):
5452 # 设置国旗图案
5553 if flag_name not in country_name :
@@ -61,22 +59,20 @@ def set_country_flag(self, flag_name):
6159 (fn + ".svg" ))).scaled (51 , 31 )
6260 self .label_national_flag .setPixmap (pixmap )
6361 self .label_national_flag .update ()
64-
65-
66- def set_lineedit_country_geometry (self ):
67- # 把lineEdit_country重叠到comboBox_country上
68- QRect1 = self .comboBox_country .geometry ()
69- QRect2 = self .horizontalWidget_country .geometry ()
70- self .lineEdit_country .setGeometry (QRect1 .x () + QRect2 .x (),
71- QRect1 .y () + QRect2 .y (),
72- QRect1 .width () - 30 , # 把箭头露出来
73- QRect1 .height ())
74-
75- def set_combobox_country (self , qtext ):
76- # 修改comboBox_country里的国家选项
62+
63+
64+ # 修改comboBox_country里的国家选项的回调
65+ def onchange_combobox_country (self , qtext ):
66+ # 记录光标位置
67+ line_edit = self .comboBox_country .lineEdit ()
68+ cursor_position = line_edit .cursorPosition ()
69+ self .comboBox_country .editTextChanged .disconnect (self .onchange_combobox_country )
7770 self .comboBox_country .clear ()
7871 self .comboBox_country .addItems (filter (lambda x : qtext in x , self .country_name ))
79-
72+ self .comboBox_country .setCurrentText (qtext )
73+ line_edit .setCursorPosition (cursor_position )
74+ self .comboBox_country .editTextChanged .connect (self .onchange_combobox_country )
75+ self .set_country_flag (qtext )
8076
8177 def setParameter (self ):
8278 self .spinBox_pixsize .setValue (self .pixSize )
@@ -90,7 +86,9 @@ def setParameter(self):
9086 self .lineEdit_label .setText (self .player_identifier )
9187 self .lineEdit_race_label .setText (self .race_identifier )
9288 self .lineEdit_unique_label .setText (self .unique_identifier )
93- self .lineEdit_country .setText (self .country )
89+ # self.lineEdit_country.setText(self.country)
90+ # self.onchange_combobox_country(self.country)
91+ self .comboBox_country .setCurrentText (self .country )
9492 self .checkBox_end_then_flag .setChecked (self .end_then_flag )
9593 self .checkBox_cursor_limit .setChecked (self .cursor_limit )
9694 self .horizontalSlider_transparency .setValue (self .transparency )
@@ -122,7 +120,7 @@ def processParameter(self):
122120 self .player_identifier = self .lineEdit_label .text ()
123121 self .race_identifier = self .lineEdit_race_label .text ()
124122 self .unique_identifier = self .lineEdit_unique_label .text ()
125- self .country = self .lineEdit_country . text ()
123+ self .country = self .comboBox_country . currentText ()
126124 self .autosave_video = self .checkBox_autosave_video .isChecked ()
127125 self .filter_forever = self .checkBox_filter_forever .isChecked ()
128126 self .board_constraint = self .lineEdit_constraint .text ()
0 commit comments