Using subscripts in text inside comboBox
Solved
QML and Qt Quick
-
Hi,
I use the QuickControls2 ComboBox in the Material style. I wanted to know whether it is possible, to use rich text for the single items, e.g. have subscripts via <sub>1</sub>. If I simply add this to the text, the <sub> are also printed in the text.
Doing my own delegate might destroy the Material style, which I want to avoid
-
Ok, the Material style source file would be here:
https://code.qt.io/cgit/qt/qtquickcontrols2.git/tree/src/imports/controls/material/ComboBox.qml -
Hi @maxwell31 ,
-
You can customize the text inside the ComboBox and provide the RichText for the text format.
For example like this:-textFormat: Text.RichText
-
To give the text Material colors, you need to provide the colors like this:-
color: Material.color(Material.Pink)
Here is the sample code:-
ComboBox { id: control width: 100 height: 100 model: ["x<sub>2</sub>" ,"x<sub>4</sub>","x<sub>3</sub>","x<sub>3</sub>"] contentItem: Text { leftPadding: 10 text: control.displayText font: control.font verticalAlignment: Text.AlignVCenter elide: Text.ElideRight textFormat: Text.RichText } delegate: ItemDelegate { width: control.width contentItem: Text { text: modelData color: Material.color(Material.Pink) font: control.font elide: Text.ElideRight verticalAlignment: Text.AlignVCenter textFormat: Text.RichText } highlighted: control.highlightedIndex === index } }
Sample Output:-
-
-
This post is deleted!