Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7195757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:38:35+00:00 2026-05-28T20:38:35+00:00

In a non-editable QComboBox, if you press some keys quickly, a search will be

  • 0

In a non-editable QComboBox, if you press some keys quickly, a search will be performed in the displayed texts and the first item which has the prefix you typed will be selected. For example, if there are six items in the combobox, “Alabama”, “Alaska”, “California”, “Colorado”, “Ohio” and “Louisiana”, and you press C, “California” will be selected. If you wait some time and press O, “Ohio” will be selected. However, if you quickly type “CO”, “Colorado” will be selected.

Is this behaviour a Qt’s feature? Apparently, this works universally, in spite of the GUI framework underneath. If it is Qt that handles this, can I customize it? What I want to do is basically perform the search based in data that is not displayed in the ComboBox. For example, in a ComboBox to select users, in which the logins are listed, it would suffice to type the user’s last name to select it. It would be enough to search for matches in the middle of the text, though (for example, typing “nia” to select “California”).

At first, QCompleter seemed to help, but it looks like it would only be useful in an editable QComboBox…

If this is not possible with QComboBox, which widget should be used to achieve this?

Thanks for the attention.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T20:38:37+00:00Added an answer on May 28, 2026 at 8:38 pm

    You subclass QComboBox and reimplement the keyPressEvent . Let’s assume that in your combo box you have implemented a function that adds an entry with two arguments: the login name and the actual name:

    void MyComboBox::addEntry(QString loginName, QString name)
    {
        addItem(loginName);
        // Store the name in a member variable, eg a map between names and login names
        namesMap.insert(name, loginName);
    }
    
    void MyComboBox::keyPressEvent(QKeyEvent *evt)
    {
        QString currentString = ebt->text();
        if (currentString.isEmpty())
        {
            QComboBox::keyPressEvent(evt);
            return; 
        } 
    
        // Iterate through the map and search for the given name
        QMapIterator<QString, QString> it(namesMap);
        while(it.hasNext())
        {
             it.next();
             QString name = it.key();
             if (name.contains(currentString))
             {
                 // it.value() is the login name corresponding to the name
                 // we have to find its index in the combo box in order to select it 
                 int itemIndex = findText(it.value());
                 if (itemIndex >= 0)
                     setCurrentIndex(itemIndex);
                 return;
             }  
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a input tag which is non editable, but some times i need
I want to make some sort of non-editable report view with images, titles and
I am using non-editable JTextPane to show some data in HTML format. I have
How do I make some rows editable and some rows non-editable in slickgrid?
I have a DataGridView with read-only mode set to true (non-editable) which takes values
I want a non-editable TextField (or a subclass) that doesn't even have the caret
In the layout you can set the EditText widget to be non-editable via the
Custom non-fatal exception derive from which class in asp.net 3.5?
I have a non-editable DataTable built with PrimeFaces. The table is initially filled with
I have a fairly pedestrian non-editable NSOutlineView setup. In the bindings for the outline

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.