The QgsVectorLayer class emits a selectionChanged() signal . If a QGIS user for example selects a record in the Attribute Table of a Vector Layer - a selectionChanged() signal is emitted an can be connected to an appropriate Slot inside the python code of a plugin. This signal is emitted every time the selection changes. I would need to realize a similar approach, but from a different direction. A signal should only be emitted when a user interaction occurs.

For example:

The user opens an attribute Table (of a vector layer) and selects one ore more records in this Table View with a mouse click. Is it possible to receive this click or select signal within a python plugin?

Does the Attribute TableView in QGIS itself emits a kind of itemSelectionChanged Signal whenever the selection of Attributes in the Table View changes? Which classes could be used to get this signal? I couldn't find any Information concerning my problem in the QGIS-API Documentation.

  • I..don t get it. Elaborate please..
    – Shepherdjo
    Commented Aug 16, 2012 at 12:15

1 Answer 1



Unless some signal is blocked or overridden somewhere along the way, QAbstractItemModel's signals should be available, e.g. dataChanged(). Also, you could access the QItemSelectionModel from QgsAttributeTableView and work with its signals, e.g. selectionChanged().

However, I'm not sure about the best means of accessing that dialog to build a signal/slot connection. It appears to be instantiated and deleted on-demand. I guess you could set up a watcher signal/slot connection at the QApplication level to the focusChanged() signal.

This would mean you either have to figure out if the focused widget is of the QgsAttributeTableDialog class or sniff out its name. Then, you could build the connection, which will disconnect when the attribute table dialog is closed and deleted.

There may be a better way, but currently the QGIS app does not emit a signal when the attribute table dialog is opened. You may want to submit a feature request for this.

Alternatively, you could create a custom feature form and add your own Python logic to it. That would work only in the instance where the user was editing a single feature, i.e. single row of the attribute table, though it is an ideal means of including verification of data input and opens up the possibilities to what you can do with what the user has entered.

  • 1
    dakcarto, thank for your answer! Unfortunately it seams, that Python Bindings do not exist for the QgsAttributeTableModel Class, so I can't use it for my Python Plugin. But your alternative suggestion could be part of a solution. The Plugin could have the necessary Table Views itself (based on QtableWidget). That would allow the best control of user interaction. Thank you!
    – klausb
    Commented Aug 17, 2012 at 10:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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