0

I am trying to use emit for the first time in PyQt. I have done a lot of reading and googling and I was sure I had this correct but I keep getting the errors shown below. Can anyone shed some light on what I am doing wrong.

def checkRiskDescription(obj,form):
    complete = True
    if str(form.txtTitle.text()) == "":
        complete = False
    if len(str(form.txtOverview.toPlainText())) < 50:
        complete = False

    bar = form.tabRiskMain.tabBar()
    if complete:
        #Change Risk Description tab to Green
        bar.setTabTextColor(0,QtGui.QColor(38, 169, 11, 255))
        form.btnSave.enabeld = True
    else:
        #Change risk Description tab to Red
        bar.setTabTextColor(0,QtGui.QColor(255, 0, 0, 255))
        form.btnSave.enabled = False

    QtGui.QWidget.emit(QtCore.SIGNAL("tabsUpdated"))

Here is the error

 File "D:\Development\python\PIF2\PIF\risk\risk.py", line 360, in checkRiskDescription
    QtGui.QWidget.emit(QtCore.SIGNAL("tabsUpdated"))
TypeError: QObject.emit(SIGNAL(), ...): first argument of unbound method must have type 'QObject'
PrestonDocks
  • 4,851
  • 9
  • 47
  • 82

1 Answers1

1

I normally just define the signal like this

tabsUpdated = Qt.pyqtSignal()

then fire it via

self.tabsUpdated.emit()

E.g

from PyQt4 import Qt

class SomeClass(Qt.QObject):
    tabsUpdated = Qt.pyqtSignal()
    def __init__(self):
        Qt.QObject.__init__(self)

    def something(self):
       #  bla bla loads of nice magic code bla bla
       self.tabsUpdated.emit()

of course the signal could be defined globally in your python file.

Neil Wightman
  • 1,103
  • 2
  • 9
  • 29