1

I'm trying QgsCheckableComboBox() in my simple python script in QGIS. How to pause code execution while a comboBox-window is open (like a dialog box)? In my example, I want to ensure that the print() function is executed only after the comboBox-window is closed. Then the checkedItems list will not be empty and will contain the selected lines ("Venus", "Earth", "Mars"). How can I achieve this?

from qgis.PyQt import QtGui
from qgis.core import *

planet_list = ["Venus", "Earth", "Mars", "Jupiter", "Pluto"]
items = QgsCheckableComboBox()
items.addItems(planet_list)
items.showNormal()

print('\n\n-----------CheckedItems: ', items.checkedItems())

Example

  • Have you tried any other approaches than the code posted? And can you clarify, the code currently executes, but the print() is not waiting for the combo box interaction? – JoshC Oct 18 at 20:49
  • No, I have not tried other approaches. Yes that's right, the print() is not waiting for the combo box interaction, but your code solved my problem! – user13892757 Oct 19 at 1:29
1

You can add the combobox to a dialog window. After closing the dialog, print prints the selected items.

from qgis.PyQt import QtGui
from qgis.core import *

planet_list = ["Venus", "Earth", "Mars", "Jupiter", "Pluto"]
items = QgsCheckableComboBox()
items.addItems(planet_list)

dlg = QDialog()
layout = QVBoxLayout()
layout.addWidget(items)
dlg.setLayout(layout)
dlg.exec_()

print('\n\n-----------CheckedItems: ', items.checkedItems())
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.