1
votes

I have a huge problem with my QTabWidget.

I have a small sample Programm, where changing the Tabs give me a message box with “current tab index:….” when I change the tab, which works ABSOLUTELY FINE:

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

Now to my Problem:

I created a GUI with QT Designer in PyQT4, which is called “abaqusian”. The QTabWidget is called "Ui_AbaqusianV1()".

The Problem is, that i have huge difficulties with emitting the Signal “currentchanged (int)”. The Pop-Up with “current tab index:….” just won`t show up when changing a tab.

Besides, the program knows the tab index, because the tab index called by the function "ongenoptions_savebutton(self)" is printed absolutely right.........what is wrong???!

Here is the code of the main program:

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

I just don`t see what is wrong. My small sample program works fine. I do exactly the same thing in my main program. Python gives me NO ERROR, but simply doesnt show the Pop-Up-Message-Window when changing the tab. I can't debug since there is no error caused.

Thanks for helping!

regards A. Neumeir

1

1 Answers

0
votes

Try this:

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

instead of this line:

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