From pykde Tue Jul 30 17:31:20 2013 From: Sebastian Sauer Date: Tue, 30 Jul 2013 17:31:20 +0000 To: pykde Subject: Re: [PyQt] PyQt4 bug bool(QComboBox()) Message-Id: <51F7F868.1090501 () dipe ! org> X-MARC-Message: https://marc.info/?l=pykde&m=137520838800654 On 07/30/2013 02:48 AM, Baz Walter wrote: > On 29/07/13 17:52, Sebastian Sauer wrote: >> >>> from PyQt4 import QtGui, QtCore >> >>> import sys >> >>> app = QtGui.QApplication(sys.argv) >> >>> c = QtGui.QComboBox() >> >>> c >> >> >>> isinstance(c,QtCore.QObject) >> True >> >>> bool(c) >> False >> >> That, bool(c) returns False, is not expected or wanted or is it? > > >>> len(c) > 0 > >>> c.addItem('foo') > >>> len(c) > 1 > >>> bool(c) > True > Thanks for the reply! I see, same with e.g. QListWidget but then: >>> c = QtGui.QTreeWidget() >>> bool(c) True >>> c = QtGui.QTableWidget() >>> bool(c) True >>> c = QtGui.QLineEdit() >>> bool(c) True >>> c = QtGui.QComboBox() >>> c.setEditable(True) >>> c.setEditText("test") >>> bool(c) False >>> c = QtGui.QComboBox() >>> v = QtGui.QTreeWidget() >>> c.setModel(v.model()) >>> c.setView(v) >>> bool(c) False >>> v.addTopLevelItems([QtGui.QTreeWidgetItem()]) >>> bool(c) True Somehow illogical or? Sure, when poking around I see e.g. QComboBox implements __len__ and not __nonzero__/__bool__, whereas QTreeWidget-item isn't iterable, etc and that explains the results. Anyhow, lesson learned: be precise when using isTrue. Thanks! :) _______________________________________________ PyQt mailing list PyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt