There is a tool `Topological coloring`, however only for polygons, not lines. You could still use it: 1. Create a (small) buffer around your lines. 2. Apply `Menu Processing / Toolbox / Topological coloring` to the buffer: it will create a new attribute `color_id`. 3. Use Categorized styling and set the color to the field `color_id`. 4. Optional: you can join the `color_id` created on your buffer layer back to your original line layer with `Join attributes by location` *The screenshot shows the solution using buffers: if they are small enough, they appear as lines:* [![enter image description here][1]][1] [1]: https://i.sstatic.net/FVHMQ.png