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. SetCurrent text of comboBox
Qt 6.11 is out! See what's new in the release blog

SetCurrent text of comboBox

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 825 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1
    ui->Lista->addItem(Nome_Config_nuovo);
    

    How can I do to set the new item as current Item?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      well you can use setCurrentIndex(int index)
      the last inserted have count() -1 as index

      ? 1 Reply Last reply
      4
      • mrjjM mrjj

        well you can use setCurrentIndex(int index)
        the last inserted have count() -1 as index

        ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        @mrjj

         ui->Lista_Configurazione->addItem(Nome_Config_nuovo);
               ui->Lista_Configurazione->setCurrentIndex(-1);
        

        I wrote this but it doesn't work, the current item is empty

        JonBJ 1 Reply Last reply
        0
        • ? A Former User

          @mrjj

           ui->Lista_Configurazione->addItem(Nome_Config_nuovo);
                 ui->Lista_Configurazione->setCurrentIndex(-1);
          

          I wrote this but it doesn't work, the current item is empty

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by
          #4

          @vale88
          That is because you have setCurrentIndex(-1). What do you expect it to set as the current item in such a circumstance, especially since https://doc.qt.io/qt-5/qcombobox.html#currentIndex-prop states:

          By default, for an empty combo box or a combo box in which no current item is set, this property has a value of -1.

          Come on, think about it first, @mrjj wrote:

          the last inserted have count() -1 as index

          ui->Lista_Configurazione->setCurrentIndex(ui->Lista_Configurazione->count() - 1);
          

          means the last item in the list (i.e. the one you have just added), doesn't it?

          1 Reply Last reply
          4

          • Login

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