What is the bug or the crash?
When calling the attributes form programmatically, via PyQGIS, the interface is not the same to what is in the GUI (right click on layer > Open Attribute Table).
This is the layer properties: as you can see fid is hidden and the fields a (but also b and c) has an alias.
Form in the GUI: everything is as expected.
Form when called with PyQGIS: does not care about what was set in the properties.
Steps to reproduce the issue
- Create a new project
- Create a new GeoPackage: Layer > Create Layer > New GeoPackage Layer
- Give it a location, eg:
my/test/path
- Give it a name, eg:
test
- Add several fields to the GeoPackage, eg:
a, b and c
- Change the Attributes Form:
- In the Layers panel: Right click on the layer
test > Properties
- In the Attributes Form tab:
- Change the type to "Drag and Drop Designer"
- Remove
fid from the right list, add aliases to the other fields (see screenshot above)
- Save your changes, click "OK"
Check the table via the GUI:
- In the Layers panel: Right click on the layer
test > Open Attribute Table
- Click "Toggle editing mode"
- Click "Add Feature"
- The UI should look like what you set in the properties.
Now check PyQGIS:
- In the Menu: Plugins > Python Console
- In the the console enter the following (replace
my/test/path by the path you set when creating the GPKG):
>>> layer = QgsVectorLayer("my/test/path/test.gpkg|layername=test", "test", providerLib="ogr")
>>> iface.showAttributeTable(layer).exec_()
- A window should open:
- Click "Toggle editing mode"
- Click "Add Feature"
- The UI does not look the same as what you set in the properties.
Versions
| QGIS version | 3.40.11-Bratislava |
| QGIS code revision | df059ed19c8 |
| |
| Libraries |
| Qt version | 5.15.8 |
| Python version | 3.11.2 |
| GDAL version | 3.6.2 |
| PROJ version | 9.1.1 |
| EPSG Registry database version | v10.076 (2022-08-31) |
| GEOS version | 3.11.1-CAPI-1.17.1 |
| SQLite version | 3.40.1 |
| PostgreSQL client version | 15.14 (Debian 15.14-0+deb12u1) |
| SpatiaLite version | 5.0.1 |
| QWT version | 6.1.4 |
| QScintilla2 version | 2.13.3 |
| OS version | Debian GNU/Linux 12 (bookworm) |
| |
| Active Python plugins |
| grassprovider | 2.12.99 |
| MetaSearch | 0.3.6 |
| db_manager | 0.1.20 |
| processing | 2.12.99 |
Supported QGIS version
New profile
Additional context
No response
What is the bug or the crash?
When calling the attributes form programmatically, via PyQGIS, the interface is not the same to what is in the GUI (right click on layer > Open Attribute Table).
This is the layer properties: as you can see
fidis hidden and the fieldsa(but alsobandc) has an alias.Form in the GUI: everything is as expected.
Form when called with PyQGIS: does not care about what was set in the properties.
Steps to reproduce the issue
my/test/pathtesta,bandctest> Propertiesfidfrom the right list, add aliases to the other fields (see screenshot above)Check the table via the GUI:
test> Open Attribute TableNow check PyQGIS:
my/test/pathby the path you set when creating the GPKG):Versions
Supported QGIS version
New profile
Additional context
No response