14

In the past I have just manually matched the color of the border to the color of the fill, but this can be time consuming.

I am wondering, is there any way to have the program automatically match the border color to that of the fill?

The fill color is being assigned through the styling tab in layer properties.

Using QGIS 2.8.6

2
  • 2
    It seems to me that removing the border will have visually the same effect than matching the border color to the fill (if the border is thin, of course). So you might want to remove the borders ("No pen" option in "border style").
    – ArMoraer
    Commented Apr 25, 2016 at 15:43
  • 4
    Thanks for the suggestion, ArMoraer. I have tried that in the past but have found that this usually exposes small gaps between the shapes, which is not aesthetically pleasing.
    – Kingfisher
    Commented Apr 25, 2016 at 15:59

4 Answers 4

24

I'm not sure how to enforce it for existing polygons, but you could make it work for any future ones that you create.

In Project Properties>Default styles>Style Manager, you could create your own default symbol style for "Fill":

QGIS Style Manager

Edit the Border color's expression and set it to @symbol_color: Editing the Border expression

Setting the border expression

Lastly, set your new fill style as the default: Setting new fill as default

This will make the border always match the set symbol color. This won't necessarily be reflected in the polygon's properties though. So it can still look like you have a different color border set in the properties, but it should always actually match the object's set symbol color in the map.

Wish I had a better idea as far as making this retroactive, but perhaps I or someone else will come along with a good idea on that later.

11
  • nice one - just tried this with an existing classified polygon layer and it worked - didn't need to set up a default style either (qgis 2.14.1)
    – Steven Kay
    Commented Apr 25, 2016 at 19:55
  • Great to hear, Steven! Setting it as a default style would be more to help not have to set it again on any new polygons in the project, but like you said, you don't necessarily have to do that.
    – JohnR
    Commented Apr 25, 2016 at 20:17
  • 2
    I installed 2.8 and tinkered with it a while. It looks like you'll need to upgrade to 2.14 if the @color_symbol function is super important, there just isn't a built in equivalent in 2.8.
    – JohnR
    Commented Apr 27, 2016 at 13:47
  • 3
    Stylistically, I like a polygon border that is a slightly darker shade of the fill color. I achieved this by defining the border color expression as: darker(@symbol_color, 200).
    – csk
    Commented Jan 18, 2017 at 20:19
  • 1
    @RutgerH I was able to get this to work on 2.18.0, but there have been minor styling changes since my initial answer. If you follow the directions and look for "Outline" instead of "Border", you should come to the same conclusion.
    – JohnR
    Commented May 24, 2017 at 14:51
4

another way to get the border color to match the fill color is to add a new layer to your symbol with the symbol layer type = Outline : Simple line.

When the color is applied at the symbol level all layer get the same color (unless one layer is locked) so the fill and the added border are the same...

enter image description here

1
  • 1
    This worked well for me. Only thing I'd add is that BEFORE styling, in the symbol selector shown above, choose the simple fill, and set the outline to "none".
    – mlinth
    Commented Sep 6 at 15:05
1

For newer QGIS versions, an option is to use an adaption of the solutions proposed to Colouring points in the same colour as their nearest point/polygon from another layer in QGIS. With overlay_nearest(), you can address features on another layer or the current layer, using the variable @layer.

The basic is to use the new overlay expressions, available since QGIS version 3.16 to get the color of the nearest (polygon) feature. Using the custom function as proposed by @Dror Bogin could help to simplify the process to build an expression for different use cases.

0

For how to make it retroactive - you can just save the style as as .qml file, use regular expression find and replace to set the borders to the same colour as the polygons (in Notepad++ or similar):

Find:

<prop k="color" v="([^\r\n"]+)"/>(.+?)<prop k="outline_color" v="([^\r\n"]+)"/>

Replace:

<prop k="color" v="\1"/>\2<prop k="outline_color" v="\1"/>

save, and then reload the style in qgis :)

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.