Skip to content

Attributes Form is not the same when called via GUI or when called via PyQGIS #65010

Description

@matthieumuller

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.

Image

Form in the GUI: everything is as expected.

Image

Form when called with PyQGIS: does not care about what was set in the properties.

Image

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 version3.40.11-Bratislava
QGIS code revisiondf059ed19c8
 
Libraries
Qt version5.15.8
Python version3.11.2
GDAL version3.6.2
PROJ version9.1.1
EPSG Registry database versionv10.076 (2022-08-31)
GEOS version3.11.1-CAPI-1.17.1
SQLite version3.40.1
PostgreSQL client version15.14 (Debian 15.14-0+deb12u1)
SpatiaLite version5.0.1
QWT version6.1.4
QScintilla2 version2.13.3
OS versionDebian GNU/Linux 12 (bookworm)
 
Active Python plugins
grassprovider2.12.99
MetaSearch0.3.6
db_manager0.1.20
processing2.12.99

Supported QGIS version

  • I'm running a supported QGIS version according to the roadmap.

New profile

Additional context

No response

Metadata

Metadata

Assignees

Labels

BugEither a bug report, or a bug fix. Let's hope for the latter!FeedbackWaiting on the submitter for answersstaleUh oh! Seems this work is abandoned, and the PR is about to close.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions