setCurrentIndex()
方法
QTabWidget
,对于此方法,您必须指示索引。每次触发信号与
QAction
菜单的
class MainWindow(QMainWindow):
def __init__(self, parent=None):
QMainWindow.__init__(self, parent)
widget = QTabWidget(self)
for i in range(10):
widget.addTab(QListWidget(), "tab{}".format(i+1))
self.setCentralWidget(widget)
menubar = self.menuBar()
action = menubar.addAction("Select tab5")
action.triggered.connect(lambda: widget.setCurrentIndex(4))
if __name__ == '__main__':
app = QApplication(sys.argv)
w = MainWindow()
w.show()
sys.exit(app.exec_())
加上:
self.Add_GroupD.triggered.connect(lambda checked, index1=4, index2=1 : self.someslot(index1, index2))
def someslot(self, index1, index2)
self.tabWidget_4.setCurrentIndex(index1)
self.tabs.setCurrentIndex(index2)