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 display ComboBox item based on value?
Qt 6.11 is out! See what's new in the release blog

How to display ComboBox item based on value?

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 972 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.
  • W Offline
    W Offline
    WhatIf
    wrote on last edited by
    #1

    Hi,

    I'm try to display one of pre-existing values of a combobox.

    ui->genderComboBox->setCurrentIndex(
                    ui->genderComboBox->findData(
                        QString::fromStdString(member->getGender())));
    

    Basically, if member->getGender() returns male or female, I want that to display. The combobox was created using qt designer.

    When I run the code above, a blank item is displayed in the combobox. If I click the drop down arrow, it displays male and female.

    Joel BodenmannJ 1 Reply Last reply
    0
    • W WhatIf

      Hi,

      I'm try to display one of pre-existing values of a combobox.

      ui->genderComboBox->setCurrentIndex(
                      ui->genderComboBox->findData(
                          QString::fromStdString(member->getGender())));
      

      Basically, if member->getGender() returns male or female, I want that to display. The combobox was created using qt designer.

      When I run the code above, a blank item is displayed in the combobox. If I click the drop down arrow, it displays male and female.

      Joel BodenmannJ Offline
      Joel BodenmannJ Offline
      Joel Bodenmann
      wrote on last edited by Joel Bodenmann
      #2

      How about QComboBox::setCurrentText(const QString& text)?

      ui->genderComboBox->setCurrentText(member->getGender());
      

      Industrial process automation software: https://simulton.com
      Embedded Graphics & GUI library: https://ugfx.io

      1 Reply Last reply
      2

      • Login

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