<div dir="ltr">Hi Larry,<div><br></div><div>Thank you so much for that! It all works as you describe, except that my QGIS doesn't show that completer where one would expect it (under the combobox), but rather at position 0,0 of the widget it is in. So that's odd. The mouse pointer is moved to the middle of the displaced completer widget, so your code works fine.</div><div><br></div><div>The other thing that doesn't work as expected, is that the mouse click doesn't transfer the entry to the combobox.</div><div><br></div><div>When I don't let the script do the mouseclick and I do it myself, it also doesn't work. (not executing the last mouseclick of your script and then doing it manually)</div><div><br></div><div>When I do arrow up or page up and then enter, it also doesn't work.</div><div><br></div><div>When I start the whole test manually, the popup appears where one would expect it and it's possible to type in the combobox's lineEdit and then mouseclick to select the value from the completer.</div><div><br></div><div>Normal:</div><div><br></div><div><div><img src="cid:ii_k77dciwn0" alt="image.png" width="343" height="65"><br></div></div><div><br></div><div>This is what happens when run from the script:</div><div><br></div><div><div><img src="cid:ii_k77dersl1" alt="image.png" width="368" height="120"><br></div></div><div>So that's weird, as if it didn't know what combobox it belongs to. The mousepointer is at the correct position though. Clicking it manually has no effect either.</div><div><br></div><div>Jo</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Feb 28, 2020 at 10:17 PM Larry Shaffer <<a href="mailto:larrys@dakotacarto.com">larrys@dakotacarto.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">Hello Jo,<div><br></div><div>Try this:</div><div><br></div><div>QTest.mouseClick(cb.lineEdit(), Qt.LeftButton)<br>QTest.keyClicks(cb.lineEdit(), '9000')</div><div>QTest.qWait(1000)<br>lv = completer.popup()<br>indx = lv.model().index(0, 0)<br>print(indx.data())<br>indx_center = lv.visualRect(indx).center()<br>QTest.mouseMove(<br> lv,<br> pos=indx_center, <br> delay=250)<br>QTest.mouseClick(<br> lv.viewport(),<br> Qt.LeftButton,<br> pos=indx_center, <br> delay=250)</div><div><br></div><div>Summary:</div><div><br></div><div>- QTest.mouseClick is sent to the combobox's QLineEdit, to set focus<br></div><div>- QTest.keyClicks should trigger your completer's list view</div><div>- QTest.qWait waits for the completer to show up (if long list, etc.)</div><div>- Instead of searching for QListView of QComboBox, ask for the completer's popup()</div><div>- Get the first index of the list view's model</div><div>- Print the index's data (text) to Python Console to verify it is the right index for test</div><div>- Find index's visual center, in global coordinates</div><div>- Move the mouse there, so you can visually verify where the click is going to occur</div><div>- Finally, click to auto-fill line edit with item from completer's list</div><div><br></div><div>Tested in QGIS 3.10.3 on macOS 10.15.3 under Python 3.8 and Qt 5.12.5.</div><div><br></div><div>Regards,<br clear="all"><div><div dir="ltr"><div dir="ltr"><br>Larry Shaffer<br>Dakota Cartography<br>Black Hills, South Dakota<br></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Feb 28, 2020 at 1:51 AM Alessandro Pasotti <<a href="mailto:apasotti@gmail.com" target="_blank">apasotti@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">I don't see anything related to QGIS in your issue, you should<br>
probably ask on a Qt/PyQt mailing list.<br>
<br>
On Fri, Feb 28, 2020 at 9:45 AM Jo <<a href="mailto:winfixit@gmail.com" target="_blank">winfixit@gmail.com</a>> wrote:<br>
><br>
> Hi,<br>
><br>
> I'm really stuck on this.<br>
><br>
> I'm trying to test a combobox with a completer:<br>
><br>
> When I do these manually, they work:<br>
><br>
> 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)<br>
><br>
> When I want to simulate them with the above commands, all I see is the popup.<br>
><br>
> I also tried the following:<br>
><br>
> 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>
> Based on what I found here:<br>
><br>
> <a href="https://gist.github.com/peteristhegreat/cbd8eaa0e565d0b82dbfb5c7fdc61c8d" rel="noreferrer" target="_blank">https://gist.github.com/peteristhegreat/cbd8eaa0e565d0b82dbfb5c7fdc61c8d</a><br>
><br>
> and here:<br>
><br>
> <a href="https://vicrucann.github.io/tutorials/qttest-signals-qtreewidget/" rel="noreferrer" target="_blank">https://vicrucann.github.io/tutorials/qttest-signals-qtreewidget/</a><br>
><br>
> I was glad I managed to translate it from C, but no joy.<br>
><br>
> Jo<br>
><br>
> On Sat, Feb 22, 2020 at 10:55 AM Jo <<a href="mailto:winfixit@gmail.com" target="_blank">winfixit@gmail.com</a>> wrote:<br>
>><br>
>> Hi,<br>
>><br>
>> I would love to add some testing code to my ever more complex application.<br>
>><br>
>> Somehow I'm not succeeding though, these are my attempts:<br>
>><br>
>> #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>
>><br>
>> The popup is the completer, I suppose, so I also tried to send keystrokes to that, but no luck.<br>
>><br>
>> This is the method I use to add the completer to the QComboBox:<br>
>><br>
>> def add_completer(self, items):<br>
>> self.setEditable(True)<br>
>> self.setInsertPolicy(0)<br>
>> completer = QCompleter(items, self)<br>
>> completer.setFilterMode(Qt.MatchContains)<br>
>> completer.setCaseSensitivity(False)<br>
>> self.setCompleter(completer)<br>
>> self.setStyleSheet('QScrollBar: vertical {width: 16px;}')<br>
><br>
> _______________________________________________<br>
> QGIS-Developer mailing list<br>
> <a href="mailto:QGIS-Developer@lists.osgeo.org" target="_blank">QGIS-Developer@lists.osgeo.org</a><br>
> List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
> Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
<br>
<br>
<br>
-- <br>
Alessandro Pasotti<br>
w3: <a href="http://www.itopen.it" rel="noreferrer" target="_blank">www.itopen.it</a><br>
_______________________________________________<br>
QGIS-Developer mailing list<br>
<a href="mailto:QGIS-Developer@lists.osgeo.org" target="_blank">QGIS-Developer@lists.osgeo.org</a><br>
List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a></blockquote></div>
_______________________________________________<br>
QGIS-Developer mailing list<br>
<a href="mailto:QGIS-Developer@lists.osgeo.org" target="_blank">QGIS-Developer@lists.osgeo.org</a><br>
List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a></blockquote></div>