Solved Using subscripts in text inside comboBox
-
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
-
Alternateively: If I need to do my own delegate, where would I find the Material style source file, so that I could copy the delegate from there?
-
Ok, the Material style source file would be here:
https://code.qt.io/cgit/qt/qtquickcontrols2.git/tree/src/imports/controls/material/ComboBox.qml -
If I understand this right, a problem with trying to copy the material style delegates for e.g. the popup is that things like
ElevationEffect
are in the implementation and thus simply copying the Material style does not work, right? -
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:-
-
-
Hi,
Thank you. I didn't see that I can change the delegate instead of changing popup!
-
A question though: Is there a simpler way to just set the textFormat property of the existing deleagte?
-
This post is deleted!