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 CurrentText of QComboBox?
Forum Updated to NodeBB v4.3 + New Features

How to set CurrentText of QComboBox?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 5.2k 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.
  • EngelardE Offline
    EngelardE Offline
    Engelard
    wrote on last edited by Engelard
    #1

    I want to set the text of this widget when no item selected yet. At the beginning my comboBox is empty, then in runtime program adds elements to this box, and i want instantly display in comboBox some string("Elemens inside"+QString::number(i)). But i can't find proper function.

    The

    ui->comboBox->setCurrentText(QString::number(i));
    

    or:

    ui->comboBox->setWindowTitle(QString::number(i));
    

    is not working, i don't know why...

    P.S. i dont need change text of first item, i need only set initial text of the header of that box.

    JonBJ 1 Reply Last reply
    0
    • EngelardE Engelard

      I want to set the text of this widget when no item selected yet. At the beginning my comboBox is empty, then in runtime program adds elements to this box, and i want instantly display in comboBox some string("Elemens inside"+QString::number(i)). But i can't find proper function.

      The

      ui->comboBox->setCurrentText(QString::number(i));
      

      or:

      ui->comboBox->setWindowTitle(QString::number(i));
      

      is not working, i don't know why...

      P.S. i dont need change text of first item, i need only set initial text of the header of that box.

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

      @Engelard
      You want to set the text in an editable QComboBox's QLineEdit widget to some string, right? In what way does ui->comboBox->setCurrentText(QString::number(i)); not work? Please be precise.

      1 Reply Last reply
      2
      • J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #3

        is your Combobox editable? if not, setCurrentText will have no effect

        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.

        http://doc.qt.io/qt-5/qcombobox.html#currentText-prop


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        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