[PyQt] QComboBox don't emit signal into a dialog box
Phil Thompson
phil at riverbankcomputing.com
Thu Oct 17 10:38:38 BST 2013
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
More information about the PyQt
mailing list