1

我的 QTabWidget 有一个很大的问题。

我有一个小示例程序,其中更改选项卡会给我一个带有“当前选项卡索引:...”的消息框。当我更改选项卡时,它绝对可以正常工作:

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 中使用 QT Designer 创建了一个 GUI,称为“abaqusian”。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

4

1 回答 1

0

尝试这个:

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

而不是这一行:

QtCore.QObject.connect(TableuGenerale, QtCore.SIGNAL(_fromUtf8("currentChanged(int)")), self.tabChangedSlot)
于 2013-09-12T09:47:54.040 回答