Search code examples
javaqtjoptionpaneqmessagebox

Use QMessageBox to choose from a list of options


I'm newly moving from Java to Qt, and I have a question. In JOptionPane you can pass an array of choices and JOptionPane will automatically make a combo box for the user to select a choice from. Is something analogous to this possible in Qt with QMessageBox or another native Qt element?


Solution

  • You should use QInputDialog::getItem(). For example:

    QStringList fruits;
    fruits << "Apple" << "Banana" ... ;
    QString fruit = QInputDialog::getItem(this, "Select fruit", "Fruit:", fruits);