I've got an idea that I'd like to try in order to extend the QGIS 3 "wordwrap" label engine function. Ultimately, I'd like to enable users to set min and max length for a single line, and then wrap the text onto as many lines as necessary.

The idea is described here, and I have been able to emulate the concept: I can emulate the result I want using a method similar to this post: Specifying Minimum and Maximum Word Wrap length in QGIS

However, I'd like to but, to make it easier to use, so I was hoping to simply create/call a brand new function that looks something like:

dynamic_wordwrap ( < string_or_field > , < min >, < max >)

It seems like I'd need to start by creating a new python function in the "Function Editor" (on the "Expression Dialog"). I thought if I could find the current code behind wordwrap(), that would be the easiest way to extend it. However, for the life of me I cannot find the actual Python code behind the wordwrap() function.

The intellisense in the Function Editor seems to be pointing me towards "worWrap" in PyQt5.QtWidgets.QLabel, or "wordWrapMode" in PyQt5.QtWidgets.PlainTextEdit, or PyQt5.QtWidgets.TextEdit, but I can't figure out how to implement these. Can someone help point me in the right direction?

1 Answer 1


It's written in C++, not python.

You can see the source here: https://github.com/qgis/QGIS/blob/master/src/core/qgsstringutils.cpp#L474

  • Well that certainly explains why I wasn't getting anywhere. Thank you. Nov 20, 2019 at 6:16

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.