I am building a plugin in python for Qgis. I want the users to be able to start typing a text and that auto compellation to pop up based on values in a certain field I will define. Is this possible and how? Is there an appropriate widget for this purpose?
In QGIS 3.0, yes. There's a QgsFieldValuesLineEdit widget which handles this for you, including background threaded load of the field values so that your application remains responsive.
You can use it by:
w = qgis.gui.QgsFieldValuesLineEdit() w.setLayer(my_vector_layer) w.setAttributeIndex(0) # or 1, 2,.. depending on which field you want to show w.show()
Full docs are available at https://qgis.org/pyqgis/3.4/gui/QgsFieldValuesLineEdit.html