2013-06-11 97 views
1

我的QTabWidget有一個很大的問題。PyQt4 QTabWidget TAB CHANGE .... currentChange(int)不起作用

我有一個小樣本PROGRAMM,其中改變標籤給我一個消息框「當前標籤指數:......。」當我改變的標籤,其精美絕倫的作品:

from PyQt4 import QtGui 
from PyQt4 import QtCore 
from PyQt4.QtCore import pyqtSlot,SIGNAL,SLOT 
import sys 

class myTabWidget(QtGui.QTabWidget): 

    def tabChangedSlot(self,argTabIndex): 
    QtGui.QMessageBox.information(self,"Tab Index Changed!", 
     "Current Tab Index: "+QtCore.QString.number(argTabIndex)); 




def main():  
    app  = QtGui.QApplication(sys.argv) 
    tabWidget  = myTabWidget() 
    tabWidget.addTab(QtGui.QWidget(),"1"); 
    tabWidget.addTab(QtGui.QWidget(),"2"); 
    tabWidget.addTab(QtGui.QWidget(),"3"); 

    #Resize width and height 
    tabWidget.resize(300,120)  
    tabWidget.setWindowTitle('QTabWidget Changed Example') 

    tabWidget.connect(tabWidget, 
     SIGNAL("currentChanged(int)"),tabWidget,SLOT("tabChangedSlot(int)")) 


tabWidget.show()  
sys.exit(app.exec_()) 

if __name__ == '__main__': 
    main() 
    「 

現在我的問題:

我在PyQT4中創建了一個名爲「abaqusian」的帶有QT Designer的GUI。 QTabWidget被稱爲「Ui_AbaqusianV1()」。

問題是,我有巨大的困難與發出信號「currentchanged(int)」。帶有「當前標籤索引:...」的彈出窗口在更改標籤時不會顯示出來。

此外,程序知道選項卡索引,因爲功能 「ongenoptions_savebutton(self)」調用的選項卡索引絕對正確地打印出來.........出錯了!

這裏是主程序的代碼:

from PyQt4 import QtCore 
from PyQt4 import QtGui 
import sys,os 
from PyQt4.QtCore import pyqtSlot,SIGNAL,SLOT 
from Tkinter import Tk 
from tkFileDialog import askopenfilename 
from tkFileDialog import askdirectory 
import Tkconstants 


class Ui_AbaqusianV1(QtGui.QTabWidget): 
    def setupUi(self, AbaqusianV1): 
     AbaqusianV1.setObjectName(_fromUtf8("AbaqusianV1")) 
     AbaqusianV1.resize(567, 530) 
     ..... 
     ..... 
     self.retranslateUi(AbaqusianV1) 
     ..... 
     QtCore.QObject.connect(self.genoptions_savebutton, QtCore.SIGNAL("clicked()"), 
      self.ongenoptions_savebutton) 

     ...... 
     TableuGenerale=Ui_AbaqusianV1() 

     QtCore.QObject.connect(TableuGenerale,QtCore 
      .SIGNAL(_fromUtf8("currentChanged(int)")), 
      self.tabChangedSlot) 

    def tabChangedSlot(self,argTabIndex): 
    QtGui.QMessageBox.information(self, 
       "Tab Index Changed!", 
       "Current TabIndex:"+QtCore.QString.number(argTabIndex)); 



    def ongenoptions_savebutton(self): 
    # Daten auslesen 
    d = {} 
    self.TableuGenerale=Ui_AbaqusianV1() 
    print "\n" 
    print "*****************************************************************" 
    print "GENERAL OPTIONS:" 
    print "\n" 
    print "Project Name: %s" % self.projectname.text() 
    print "Save location Abaqusian: %s" % abaqusian_dir 
    print "Save location Inp. Files: %s" % inpfiles_dir 
    print "\n" 
    print "current tab index is: %s" % self.TableuGenerale.currentIndex() 
    print "GENERAL OPTIONS ----> SAVED" 
    print "*****************************************************************" 

..... 
..... 
..... 
if __name__ == "__main__": 
    app = QtGui.QApplication(sys.argv) 
    AbaqusianV1 = QtGui.QTabWidget() 
    ui = Ui_AbaqusianV1() 
    ui.setupUi(AbaqusianV1) 
    AbaqusianV1.show() 
    sys.exit(app.exec_()) 

我只是不`噸看看什麼是錯的。 我的小示例程序正常工作。 我在主程序中完全一樣。 Python給了我沒有錯誤,但改變選項卡時根本不顯示彈出消息窗口。 由於沒有錯誤導致我無法調試。

感謝您的幫助!

問候 A. Neumeir

回答

0

試試這個:

QtCore.QObject.connect(self, QtCore.SIGNAL(_fromUtf8("currentChanged(int)")), self.tabChangedSlot) 

,而不是這一行:

QtCore.QObject.connect(TableuGenerale, QtCore.SIGNAL(_fromUtf8("currentChanged(int)")), self.tabChangedSlot)