Accessing 'ok' parameter from QInputDialog

Hello,
I’m using a simple input dialog to get a user choice from a list but need to determine if the Cancel button has been pushed. I understand slicer uses PythonQt and it looks like PythonQt provides a BoolResult type to do this. However, I haven’t been able to get this working. The following code just causes slicer to crash.

result = PythonQt.BoolResult()
item = qt.QInputDialog().getItem(None, "MyTitle", "Enter text", ['Choice1', 'Choice2'], ok=result)

Any help would be appreciated.

It was quite close. This works:

import PythonQt
selectionSuccess = PythonQt.BoolResult()
selectedItem = PythonQt.QtGui.QInputDialog().getItem(None, "MyTitle", "Label", ['Choice1', 'Choice2'], 1, True, selectionSuccess)

Note that popup windows are generally very annoying for users and should only be used in exceptional cases. I would recommend to add these widgets to your module’s GUI panel instead (by using Qt Designer).

Perfect. Thank you.
Yes, popup window is only to cater for low traffic pathway through the workflow (trying to avoid cluttering the module pane).