Started building my first plugin in qgis and looking for a way to create dynamic widget in pyqyt and Qt designer which allow user to add or delete parameters as much as he want (something like a '+' and '-' buttons). The goal is to get from the user list of layers and some other parameters which describe user preference for each layer (some other strings, fields etc). Looked for some table widget and didn't find some useful base neither in qt designer nor in the code part. The result widget should look something like that:
layer1. Field1. Str1. Bool1
layer2. Field2. Str2. Bool2
layer3. Field3. Str3. Bool3
…
Add Layer button | Remove layer button
Best Answer
You can get something like this :
The
+
button allow the user to add a new line, and the-
button remove the last line. It's possible to remove the selected line with theselectedIndexes()
method from the QAbstractItemView Class. TheGet Value
button print a dictionary in the python console with an element for each row and a list with all the values.Here is the full code, it works in the QGIS Python Console :