Starter2
Starter2

Reputation: 57

Trouble disabling buttons in PYQT4

Hi I have a GUI from with select a file to be processed.

When he click "process" I want the buttons ("quit" and "process") to be disable. I've tried " self.Qbtn.setEnabled(False) ", nut it doesn't seems to work. The buttuon stay as usual.

This is a condensed code of what it is, the function take about 2 sec to be processed. Do you see something odd? Any advice? Python 2.7.3, Pyqt4

class GuiPTCR(QtGui.QWidget): (the indent is ok)
def __init__(self):
    super(GuiPTCR, self).__init__()

    self.initUI()

def initUI(self):        
    self.Qbtn = QtGui.QPushButton('Quitter'.decode('utf-8').encode(enco), self)
    self.Qbtn.clicked.connect(QtCore.QCoreApplication.instance().quit)  #    QtCore.QCoreApplication.instance().quit
    self.Qbtn.setToolTip('Quitter'.decode('utf-8').encode(enco))
    self.Qbtn.resize(self.Qbtn.sizeHint())

    self.btnTraiter = QtGui.QPushButton("Traiter".decode('utf-8').encode(enco))
    self.btnTraiter.clicked.connect(self.Traiter1)   

def Traiter1(self):
    import os

    self.Qbtn.setEnabled(False)
    self.btnTraiter.setEnabled(False)

    fichierRes = Traiter()

    self.Qbtn.setEnabled(True)
    self.btnTraiter.setEnabled(True)

    self.res.setText("Fait en {:.2f} secondes".format(elapsed))
    if self.OuvrirRes.checkState() == 2:
        os.startfile(fichierRes)

Upvotes: 1

Views: 2594

Answers (1)

numentar
numentar

Reputation: 1079

You can try calling QtGui.QApplication.processEvents() just before calling Traiter(). Read more here:

Upvotes: 2

Related Questions