<div dir="ltr">Hi,<br><div><br></div><div>I'm really stuck on this.</div><div><br></div><div>I'm trying to test a combobox with a completer:</div><div><br></div><div>When I do these manually, they work:</div><div><br></div><div> cb = self.form.dockwidget.widget['sc_510_002']<br> QTest.keyClicks(cb, '9000')<br> QTest.qWait(1000)<br> QTest.keyClick(cb, Qt.Key_PageUp, Qt.NoModifier, 500)<br> QTest.keyClick(cb, Qt.Key_Enter, Qt.NoModifier, 500)</div><div><br></div><div>When I want to simulate them with the above commands, all I see is the popup.</div><div><br></div><div>I also tried the following:</div><div><br></div><div> cb = self.form.dockwidget.widget['sc_510_002']<br> QTest.keyClicks(cb, '9000')<br> lv = cb.findChild(QListView)<br> QTest.qWait(1000)<br> QTest.mouseClick(lv.viewport(), Qt.LeftButton, 0, lv.visualRect).center())<br><br></div><div>Based on what I found here:</div><div><br></div><div><a href="https://gist.github.com/peteristhegreat/cbd8eaa0e565d0b82dbfb5c7fdc61c8d">https://gist.github.com/peteristhegreat/cbd8eaa0e565d0b82dbfb5c7fdc61c8d</a> </div><div><br></div><div>and here:</div><div><br></div><div><a href="https://vicrucann.github.io/tutorials/qttest-signals-qtreewidget/">https://vicrucann.github.io/tutorials/qttest-signals-qtreewidget/</a></div><div><br></div><div>I was glad I managed to translate it from C, but no joy.</div><div><br></div><div>Jo <br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Feb 22, 2020 at 10:55 AM Jo <<a href="mailto:winfixit@gmail.com">winfixit@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi,<br><div><br></div><div>I would love to add some testing code to my ever more complex application.</div><div><br></div><div>Somehow I'm not succeeding though, these are my attempts:</div><div><br></div><div>#form.dockwidget.widget['sc_510_002'].setCurrentIndex(5) # , doing it directly doesn't work<br>QTest.keyClicks(form.dockwidget.widget['sc_510_002'], '9000 Gent', Qt.NoModifier, 50) # this works, a popup appears<br>QTest.keyClick(form.dockwidget.widget['sc_510_002'], Qt.Key_Enter, Qt.NoModifier, 500)<br>QTest.keyClick(form.dockwidget.widget['sc_510_002'], Qt.Key_Tab, Qt.NoModifier, 500)<br>#QTest.keyClick(form.dockwidget.widget['sc_510_002'].completer, Qt.Key_Down, Qt.NoModifier, 500)<br>#print(dir(form.dockwidget.widget['sc_510_002'].completer().widget()))<br>#form.dockwidget.widget['sc_510_002'].completer().setCurrentRow(0)<br>#QTest.keyClick(form.dockwidget.widget['sc_510_002'].completer().widget().lineEdit(), Qt.Key_Enter, Qt.NoModifier, 500)<br>#form.dockwidget.widget['sc_510_002'].setEditText('1000 Brussel')<br></div><div><br></div><div>The popup is the completer, I suppose, so I also tried to send keystrokes to that, but no luck.</div><div><br></div><div>This is the method I use to add the completer to the QComboBox:</div><div><br></div><div><pre style="color:rgb(0,0,0);font-family:"Courier New";font-size:10.5pt"><span style="color:rgb(0,0,128);font-weight:bold">def </span>add_completer(<span style="color:rgb(148,85,141)">self</span>, items):<br> <span style="color:rgb(148,85,141)">self</span>.setEditable(<span style="color:rgb(0,0,128);font-weight:bold">True</span>)<br> <span style="color:rgb(148,85,141)">self</span>.setInsertPolicy(<span style="color:rgb(0,0,255)">0</span>)<br> completer = QCompleter(items, <span style="color:rgb(148,85,141)">self</span>)<br> completer.setFilterMode(Qt.MatchContains)<br> completer.setCaseSensitivity(<span style="color:rgb(0,0,128);font-weight:bold">False</span>)<br> <span style="color:rgb(148,85,141)">self</span>.setCompleter(completer)<br> <span style="color:rgb(148,85,141)">self</span>.setStyleSheet(<span style="color:rgb(0,128,128);font-weight:bold">'QScrollBar: vertical {width: 16px;}'</span>)</pre></div></div>
</blockquote></div>