I struggled a bit with the Geometry generator
as @GSienko. For intersection part you can also use built-in function aggregate
. Also I used segment_to_lines
function which convert polygons to lines.
difference(
segments_to_lines($geometry),
aggregate(
layer:= 'line',
aggregate:='collect',
expression:= $geometry,
filter:=intersects($geometry, geometry(@parent))
)
)
or
difference(
segments_to_lines($geometry),
aggregate('line','collect',$geometry,intersects($geometry, geometry(@parent)))
)
If you have some polygon "unrelated" to lines you can add if
condition for intersection. If layers are in intersection, then difference is applied for symbology, otherwise whole geometry is applied.
if(
intersects(
segments_to_lines($geometry),
aggregate('line','collect',$geometry,intersects($geometry, geometry(@parent)))
),
difference(
segments_to_lines($geometry),
aggregate('line','collect',$geometry,intersects($geometry, geometry(@parent)))
),
segments_to_lines($geometry)
)
edit: Using line generator this way has a weak point - you have to handle legend symbol, because it render line thru the polygon (not as a border). However you can still duplicate the layer, set simple fill and use it for legend.