I would like to set dynamic line width and it should be scaled by the value "Stroke width".

When I set the value to 0.15, it will be less than 0.15 if $length is too small. I need a function to get the value set in "Stroke width" so that I can modify it directly in "Stroke width" instead of in Expression String builder.

  WHEN ($length < 1) THEN ($length * 0.15 / 1)
  WHEN ($length >= 1) THEN (0.15)



  • 1
    you may be interested in scale_linear(val, domain_min, domain_max, range_min, range_max) or scale_exp(val, domain_min, domain_max, range_min, range_max, exponent). Something like scale_linear("Stroke width", min("Stroke width"), max("Stroke width"), 1, 5) in Map Units – Taras Apr 12 at 7:51

You refer to "stroke width" in double quotation marks, which makes it seem like your attribute table has a field called "stroke width." If that's the case, you can use this field in an expression, and scale the line width based on the value in the stroke width field.

enter image description here enter image description here

If, as I suspect, you're actually talking about the stroke width box in the layer styling panel enter image description here, then you can't do what you're asking for. QGIS just isn't designed that way. The value set in the stroke width box is not available in the expression builder. The Data-Defined Override setting will always override the value you enter into the stroke width box. See the second and third definitions of "override" from dictionary.com:

  1. to disregard, set aside, or nullify; countermand
  2. to take precedence over; preempt or supersede

What you can do instead is define a custom variable in the layer properties. Eg, you could call your variable default_stroke_width. Once the variable is defined, you can use it in the expression builder with @default_stroke_width.

enter image description here

enter image description here

Even though this variable has the words "stroke width" in its name, it's not connected to the stroke width box in the style panel. When you want to change the default_stroke_width value, you'll have to go back into layer properties and edit the variable. This is probably less convenient than editing the expression itself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.