We are building a graphical user interface with QtQuick/QML. We have some dynamic, multi-line text coming from a database, which should be displayed in the application. Currently, we are using the Text
element to display the text. However, we need some QML components inline embedded into the text. For this, the text coming from the database contains placeholders such as ::checkbox|1::
which should then be replaced and displayed by the program.
In HTML, this is easy, you can simply mix inline elements with text to produce a result like this:
but in QML, this seems to be more difficult, as Text
elements cannot be word-wrapped into two halves if there is not enough space (both the text and the container size should be dynamic).
The best solution we could come up with, is creating a Flow
layout with one Text
element for each word, but this seems too hacky.
Using RichText
with HTML is not enogh, since we really need our custom QML elements in the text.
Also, we want to avoid using a WebView
due to performance reasons.
Is there a sophisticated way to implement this with QML/C++ only?
Text
orButton
or whatever ant put that intoFlow
. Yes, in this case you lose all text alignments, space rules etc. – folibis