Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QComboBox - setCurrentText???
Qt 6.11 is out! See what's new in the release blog

QComboBox - setCurrentText???

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 42.3k 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.
  • R Offline
    R Offline
    ronM71
    wrote on last edited by
    #1

    I can "getCurrentText". Why not be able to "set" current text as if the user just typed it. I don't want to add it to the drop down list, just change the current text. Is that possible?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      This should work:

      @
      QString textToFind = "abc";
      int index = ui->comboBox->findText(textToFind)
      ui->comboBox->setCurrentIndex(index);
      @

      There is no setter, as the texts need not be distinct, thus the setter would not know which index to make the current.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • R Offline
        R Offline
        ronM71
        wrote on last edited by
        #3

        please correct me if I got confused here.

        If "abc" isn't found the index returned by "findText" is -1 in which case, the setCurrentIndex will not work. Your code only works if "abc" already exists somewhere within the dropdown items, setting item "0" (the currently shown) to it.

        My intention was to programmatically simulate a situation where a user clicks on the edit-box portion of the drop down, and types something, regardless of whether it exists in the dropdown items, which brings me to this question: will a user-typing actually change the "item 0" in real time?

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          You are right in your analysis. You can get access to the embedded line edit in the combo box...

          1 Reply Last reply
          0
          • R Offline
            R Offline
            ronM71
            wrote on last edited by
            #5

            Yes. Thanks Volker and Andre. I now see the:

            @QLineEdit * lineEdit () const@

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #6

              Maybe "QComboBox::setItemText() ":http://doc.qt.nokia.com/4.7/qcombobox.html#setItemText in pair with currentIndex () fits your need too.

              http://www.catb.org/~esr/faqs/smart-questions.html

              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