[QGIS-Developer] Testing a ComboBox with a QCompleter using QTest
Jo
winfixit at gmail.com
Sat Feb 22 01:55:53 PST 2020
Hi,
I would love to add some testing code to my ever more complex application.
Somehow I'm not succeeding though, these are my attempts:
#form.dockwidget.widget['sc_510_002'].setCurrentIndex(5) # , doing it
directly doesn't work
QTest.keyClicks(form.dockwidget.widget['sc_510_002'], '9000 Gent',
Qt.NoModifier, 50) # this works, a popup appears
QTest.keyClick(form.dockwidget.widget['sc_510_002'], Qt.Key_Enter,
Qt.NoModifier, 500)
QTest.keyClick(form.dockwidget.widget['sc_510_002'], Qt.Key_Tab,
Qt.NoModifier, 500)
#QTest.keyClick(form.dockwidget.widget['sc_510_002'].completer,
Qt.Key_Down, Qt.NoModifier, 500)
#print(dir(form.dockwidget.widget['sc_510_002'].completer().widget()))
#form.dockwidget.widget['sc_510_002'].completer().setCurrentRow(0)
#QTest.keyClick(form.dockwidget.widget['sc_510_002'].completer().widget().lineEdit(),
Qt.Key_Enter, Qt.NoModifier, 500)
#form.dockwidget.widget['sc_510_002'].setEditText('1000 Brussel')
The popup is the completer, I suppose, so I also tried to send keystrokes
to that, but no luck.
This is the method I use to add the completer to the QComboBox:
def add_completer(self, items):
self.setEditable(True)
self.setInsertPolicy(0)
completer = QCompleter(items, self)
completer.setFilterMode(Qt.MatchContains)
completer.setCaseSensitivity(False)
self.setCompleter(completer)
self.setStyleSheet('QScrollBar: vertical {width: 16px;}')
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20200222/9de52d52/attachment.html>
More information about the QGIS-Developer
mailing list