2017-09-25 79 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

相關問題