I have a polygon vector layer with Simple line symbology. When I select one from Attribute table, QGIS change the boundary color in yellow, but I have difficulties to find it easily between many polygons. I need every time to click on "Zoom to the selected rows". Is there a way to fill with color a polygon when it is selected as ArcGIS software?
3 Answers
Create a new symbol layer of Geometry Generator and Simple Fill type with this expression:
case when is_selected() then $geometry end
This creates a new style that is used for selected polygons only.
To change the color of selected features, go to
Menu Settings > Options > Tab Canvas&Legends > Selection Color
.
Since I couldn't find a manual solution, I use a script for that kind of purpose. Run the following script in QGIS Python Editor. It opens the attribute table of the layer. When you select a row in the table, it zooms to the selected feature automatically.
layer_name = "polygon_layer"
lyr = QgsProject.instance().mapLayersByName(layer_name)[0]
def zoom_selected_feature(i):
iface.mapCanvas().zoomToSelected(lyr)
iface.mapCanvas().zoomByFactor(2)
#lyr.removeSelection()
attr_table = iface.showAttributeTable(lyr)
table = attr_table.findChildren(QTableView)[0]
table.verticalHeader().sectionClicked.connect(zoom_selected_feature)
-
The script is quite interesting, but what I needed was the Babel's solution. Thanks anyway– LionCommented Nov 29, 2022 at 14:49
A third, and manual, alternative to the other two answers currently posted, is to change the polygon layer's symbology from Outline: Simple Line to Simple Fill with a transparent fill. That's done by
- Navigating to the layer's symbology properties.
- Choosing Symbol layer type = Simple Fill in dropdown.
- Picking Fill color = Transparent Fill as shown below.
QGIS will then show outlines for unselected polygons in the layer and fill the polygons which are selected. (As of QGIS 3.22.14 setting the layer's Fill style to No Brush also produces this result, regardless of the fill color chosen.) For example, with the default yellow selection color a single selected polygon would then look something like this: