2017-09-25 78 views

回答

2

要打开,你必须使用QTabWidgetsetCurrentIndex()方法的标签,这种方法必须注明指数。以上每次必须执行与菜单

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_()) 

QAction加上相关的触发信号:

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) 
+0

这个工作谢谢,但我有somemore在这里做。我有标签内的标签,我想要导航说按钮点击后,我得到选项卡5,现在我想在Tab2内tab5 ..你能帮我这吗?对不起,我现在延长我的问题:) –

+0

缺少什么? – eyllanesc

+0

显示您的代码以更好地理解,我明白,通过单击按钮访问tab5,就像我在示例中显示的那样,在选择嵌套tab2之前哪个操作? – eyllanesc

相关问题