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. ComboBox: change text in dropdown
QtWS25 Last Chance

ComboBox: change text in dropdown

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 505 Views
  • 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
    Mark81
    wrote on last edited by
    #1

    The displayText property allows to change the visualization of the current item. For example:

    ComboBox {
        model: myModel
        displayText: currentText.replace('*','');
    }
    

    Now if the item contains a '*' it will be removed. But this happens only when the combo box is closed. I want to do the same also when the dropdown is open. How to do this?

    ODБOïO 1 Reply Last reply
    0
    • M Mark81

      The displayText property allows to change the visualization of the current item. For example:

      ComboBox {
          model: myModel
          displayText: currentText.replace('*','');
      }
      

      Now if the item contains a '*' it will be removed. But this happens only when the combo box is closed. I want to do the same also when the dropdown is open. How to do this?

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      @Mark81 hi,
      One way to do that is writing your own delegate for the ComboBox

      ComboBox {
              model: ["ds*f","f","ff*f"]
              displayText: currentText.replace('*','');
              delegate:
                  Text{
                      text : modelData.replace('*','');
                  }
          }
      

      or just clean your model before passing it to your ComboBox

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

        Got it. I'm going to follow the second (and more obvious solution) because otherwise I need to rewrite the handling for colors, highlights, etc... I thought there was a way to override just the items' text.

        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