5

I want to edit many features in the attribute table, for which I have to see imagery in the background of the features. To speed the process up, ideally I do not want to use the mouse to click somewhere.

Right now I can edit a field, tab to jump to next field, edit, ... When finished with the last attribute of a feature using tab will jump to the first attribute of the next feature (which is nice), but then I would like to pan/zoom to that feature (Str + P/ Str + J) which is only possible if the entire line is selected.

So either I would like to know how to select a column in the attribute table with keyboard shortcut?

The question was asked in Keyboard shortcut to select entire column in attributes table QGIS already, but my use case is different and I wonder if there is a way for that.

Or alternatively I would like to zoom to that feature automatically.

1
  • Please check my updated answer :-)
    – Ben W
    Commented Jun 16, 2022 at 3:59

1 Answer 1

5

You can use the script below to open your layer's attribute table with the behavior you describe temporarily implemented.

To run the script, open the Python console, open a new blank editor, paste in the script below, make sure the layer you are working on is the active layer in the TOC panel, then click the green 'Play' button to execute the script. The attribute table for your layer will be opened. Now, every time you tab from the last column of one row to the first cell of the next row, the canvas will zoom automatically to that feature.

lyr = iface.activeLayer()

att_tbl = iface.showAttributeTable(lyr)

tbl_view = att_tbl.findChildren(QTableView)[0]

sel_mod = tbl_view.selectionModel()
    
def row_changed(current, previous):
    feature_id = current.model().data(current, QgsAttributeTableModel.FeatureIdRole)
    iface.mapCanvas().zoomToFeatureIds(lyr, [feature_id])
    
sel_mod.currentRowChanged.connect(row_changed)

Quick & dirty demo which shows the expected behavior:

enter image description here

8
  • Will a person need some special imports ?
    – Taras
    Commented Jun 15, 2022 at 5:29
  • 1
    Wow!! Such a small world! :-)
    – Ben W
    Commented Jun 15, 2022 at 6:39
  • 1
    Thanks, that's working! Although it has the limitation that an id column exists, as you said. Further this column is not allowed to be hidden. And at project restart you have to run the script again. So it's great for now but might be worth to add as a function in future QGIS versions. Commented Jun 15, 2022 at 9:16
  • 1
    @jens wiesehahn, Good news- I have edited my answer. I only had to dig a little in the source code. With this method you do not need an 'id' column at all. You are right, it would probably be useful feature which I would be happy to develop. When I get time I will try to make a pull request to add this functionality to a future release.
    – Ben W
    Commented Jun 16, 2022 at 3:41
  • 2
    I just testet to replace zoomToFeatureIds() by panToFeatureIds() to keep the scale when switching to the next feature and it also works. :) Commented Jun 21, 2022 at 9:20

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.