[PyQt] QComboBox don't emit signal into a dialog box
Phil Thompson
phil at riverbankcomputing.com
Thu Oct 17 11:18:24 BST 2013
On Thu, 17 Oct 2013 11:51:21 +0200, Vincent Vande Vyvre
<vincent.vandevyvre at swing.be> wrote:
> Le 17/10/2013 11:38, Phil Thompson a écrit :
>> On Thu, 17 Oct 2013 11:20:43 +0200, Vincent Vande Vyvre
>> <vincent.vandevyvre at swing.be> wrote:
>>> When placed into a dialog box the QComboBox don't emit any signal if
the
>>> user activate it.
>>>
>>> When the current item is changed by the program, the signal is
correctly
>>> emitted.
>>>
>>> Python 2.7, Qt: 4.8.1, PyQt: 4.9.1
>>> Python 3.2, Qt: 4.8.1, PyQt: 4.9.1
>>>
>>> Example
>>>
>>> from PyQt4 import QtGui
>>>
>>> class Editor(object):
>>> def __init__(self, Dial):
>>> super(Editor, self).__init__()
>>> self.grid = QtGui.QGridLayout(Dial)
>>> self.cmb = QtGui.QComboBox(Dial)
>>> self.grid.addWidget(self.cmb, 0, 0, 1, 1)
>>> self.cmb.addItems(['One', 'Two', 'Three'])
>>> self.cmb.currentIndexChanged.connect(self.index_changed)
>>> self.cmb.activated.connect(self.index_changed)
>>> self.btn = QtGui.QPushButton('Quit', Dial)
>>> self.grid.addWidget(self.btn, 1, 0, 1, 1)
>>> self.btn.clicked.connect(Dial.accept)
>>>
>>> self.cmb.setCurrentIndex(1)
>>>
>>> def index_changed(self, idx):
>>> print('Index:', idx)
>>>
>>> app = QtGui.QApplication([])
>>> Dial = QtGui.QDialog()
>>> Editor(Dial)
>>> reply = Dial.exec_()
>>>
>>> With Qt: 5.0.2 + PyQt: 5.0 no problem, that's works.
>> Keep a reference to your Editor instance.
>>
>> Phil
>>
> You'r right, that's works.
>
> Strange behavior ...
There is nothing strange about it at all. The Editor instance is being
garbage collected. The signal is being emitted as you would expect but the
slot it was connected to no longer exists.
Phil
More information about the PyQt
mailing list