Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    QComboBox - setCurrentText???

    General and Desktop
    3
    6
    37118
    Loading More Posts
    • 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
      ronM71 last edited by

      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 Reply Quote 0
      • G
        goetz last edited by

        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 Reply Quote 0
        • R
          ronM71 last edited by

          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 Reply Quote 0
          • A
            andre last edited by

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

            1 Reply Last reply Reply Quote 0
            • R
              ronM71 last edited by

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

              @QLineEdit * lineEdit () const@

              1 Reply Last reply Reply Quote 0
              • G
                goetz last edited by

                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 Reply Quote 0
                • First post
                  Last post