Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Using subscripts in text inside comboBox
Forum Updated to NodeBB v4.3 + New Features

Using subscripts in text inside comboBox

Scheduled Pinned Locked Moved Solved QML and Qt Quick
8 Posts 2 Posters 1.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maxwell31
    wrote on last edited by maxwell31
    #1

    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

    1 Reply Last reply
    0
    • M Offline
      M Offline
      maxwell31
      wrote on last edited by
      #2

      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?

      1 Reply Last reply
      0
      • M Offline
        M Offline
        maxwell31
        wrote on last edited by
        #3

        Ok, the Material style source file would be here:
        https://code.qt.io/cgit/qt/qtquickcontrols2.git/tree/src/imports/controls/material/ComboBox.qml

        1 Reply Last reply
        0
        • M Offline
          M Offline
          maxwell31
          wrote on last edited by
          #4

          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?

          1 Reply Last reply
          0
          • Shrinidhi UpadhyayaS Offline
            Shrinidhi UpadhyayaS Offline
            Shrinidhi Upadhyaya
            wrote on last edited by Shrinidhi Upadhyaya
            #5

            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:-

            0_1559208483247_6a446b37-fb6b-4f69-a009-8c585e653116-image.png

            0_1559208542160_561efd40-4f24-4fa5-950c-1ef497ed3ae1-image.png

            1 Reply Last reply
            5
            • M Offline
              M Offline
              maxwell31
              wrote on last edited by
              #6

              Hi,

              Thank you. I didn't see that I can change the delegate instead of changing popup!

              1 Reply Last reply
              0
              • M Offline
                M Offline
                maxwell31
                wrote on last edited by
                #7

                A question though: Is there a simpler way to just set the textFormat property of the existing deleagte?

                1 Reply Last reply
                0
                • Shrinidhi UpadhyayaS Offline
                  Shrinidhi UpadhyayaS Offline
                  Shrinidhi Upadhyaya
                  wrote on last edited by
                  #8
                  This post is deleted!
                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved