[PyQt] QComboBox don't emit signal into a dialog box

Sebastian Elsner sebastianelsner at freenet.de
Thu Oct 17 10:27:22 BST 2013


I think your Editor class should inherit from QObject, not object. Does 
it work then?


On 10/17/2013 11:20 AM, Vincent Vande Vyvre 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.
>



More information about the PyQt mailing list