自己本来就是业余的新手,三个月前的练手项目,这两天打开要修改东西,忘了好多。我想把创建 comboBox 之后的代码换到另一个方法内,self.comboBox.activated[int].connect(self.connectComboBox)却不执行了。麻烦朋友帮看一下是什么原因:
def setupUi(self,parent):
widget = QWidget()
widget.setObjectName('Ui_Chinese')
parent.setCentralWidget(widget)
self.comboBox = QComboBox(widget)
self.comboBox.setGeometry(10, 200, 155, 25)
self.comboBox.setView(QListView())
self.comboBox.addItems(['选择题型', '汉字学习', '拼音学习', '故事阅读'])
self.comboBox.activated[int].connect(self.connectComboBox)
self.comboBox.setMaxVisibleItems(10)
# 只想要以上代码,但是 self.comboBox.activated[int].connect(self.connectComboBox)没有进入槽函数
self.scroll = QScrollArea(widget)
self.vbar = self.scroll.verticalScrollBar()
self.frameData = QFrame()
self.frameData.setObjectName('frameData')
gridData = QGridLayout()
self.frameData.setLayout(gridData)
hanziData = json.load(open('chineseData.json', 'r', encoding='utf-8'))
row = 0
column = 0
for hanzi in hanziData:
btn = QPushButton(hanzi)
btn.setFixedSize(100, 100)
btn.clicked.connect(self.connectframeData(hanzi))
gridData.addWidget(btn, row, column)
# 我一句一句试着,结果是到这一句以上补上的话,
# self.comboBox.activated[int].connect(self.connectComboBox)就执行槽函数,
# 少了 gridData.addWidget(btn, row, column)这句都不行,后面的怎么添加都不影响。
column += 1
if column == 5:
row += 1
column = 0
self.frameData.setMinimumSize(540, (row+1)*100)
self.scroll.setGeometry(350, 200, 562, 430)
self.scroll.setWidget(self.frameData)
self.scroll.setAutoFillBackground(True)
def connectComboBox(self, index):
if index == 1:
print(1)
# self.scroll.show()
# self.frameControl.show()
else:
print(3)
# self.scroll.hide()
# self.frameControl.hide()
if index == 2:
print(2)
麻烦朋友们帮帮忙,三个月不弄这都快忘完了,谢谢大佬了,我就是一业余的。