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. How to set the current index in QCombo box

How to set the current index in QCombo box

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 3.4k 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.
  • S Offline
    S Offline
    summit
    wrote on last edited by Christian Ehrlicher
    #1

    this is the code i am using for QComboBox

    QComboBox *comboboxAlignment = new QComboBox;
    
    comboboxAlignment->addItem("Left");
    comboboxAlignment->addItem("Center");
    comboboxAlignment->addItem("Right");
    

    like we can set the index of combo box using a int value comboboxAlignment->setCurrentIndex(0)

    can i do it by passing the string value for example if is pass "Right" than the item in the combo box having "Right" as text should become current item.

    JonBJ 1 Reply Last reply
    0
    • S summit

      this is the code i am using for QComboBox

      QComboBox *comboboxAlignment = new QComboBox;
      
      comboboxAlignment->addItem("Left");
      comboboxAlignment->addItem("Center");
      comboboxAlignment->addItem("Right");
      

      like we can set the index of combo box using a int value comboboxAlignment->setCurrentIndex(0)

      can i do it by passing the string value for example if is pass "Right" than the item in the combo box having "Right" as text should become current item.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @summit
      setCurrentText(const QString &text)

      The setter setCurrentText() simply calls setEditText() if the combo box is editable. Otherwise, if there is a matching text in the list, currentIndex is set to the corresponding index.

      1 Reply Last reply
      3

      • Login

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