Problems with Open-Source Downloads read https://www.qt.io/blog/problem-with-open-source-downloads and https://forum.qt.io/post/638946

Focus inside QComboBox



  • Hello!

    I have an application that is handled with a joystick.

    I have a list of parameters and one of this parameters is a QComboBox. I am simulating the joystick positions with the letters 'a' (left movement), 'd' (right movement), 'w' (up movement), 's' (down movement) and 'f' (enter).

    There is an eventFilter in which I do all but, when I enter in the QComboBox, I can't navigate between its options. How can I give the focus to the QComboBox entries?

    Thank you very much!



  • If your questions is how to get certain things inside a QcomboBox for you to select as a dropdown - this should work:

    QComboBox combo;
           QObject::connect(&combo, &QComboBox::currentTextChanged, [&]{
              std::cout << combo.currentText().toStdString() << std::endl;
           });
           for (auto const & info : [whatever the variable is you want to parse goes here])
              ui->comboBox->addItem([the variables you parsed get added here], 0);
    

    For example I used this to get all the cameras that are plugged in to my PC:

    QComboBox combo;
           QObject::connect(&combo, &QComboBox::currentTextChanged, [&]{
              std::cout << combo.currentText().toStdString() << std::endl;
           });
           for (auto const & info : QCameraInfo::availableCameras())
              ui->comboBox->addItem(info.description(), 0);
    


  • @ivanicy

    You could navigate through your QComboBox items by using

    https://doc.qt.io/qt-5/qcombobox.html#currentIndex-prop

    Use setCurrentIndex(int) and increase the index, for example, when pressing S (down) and decrease (up), when pressing W.


Log in to reply