wxSearchCtrl has a search button, and auto complete like the search input in Google Maps.
However, in Google Maps the autocomplete makes a list of items show beneath the input text control.
If I want to implement a similar feature in wxWidgets, what would be the place to start?
wxSearchCtrl like Google Maps
Re: wxSearchCtrl like Google Maps
Any class that derives from wxTextEntry has autocomplete functionality:
http://docs.wxwidgets.org/trunk/classwx_text_entry.html
Just use a wxComboBox and use a static list of strings or derive your own class from wxTextCompleter for more fancy stuff.
http://docs.wxwidgets.org/trunk/classwx_text_entry.html
Just use a wxComboBox and use a static list of strings or derive your own class from wxTextCompleter for more fancy stuff.
Use the source, Luke!
Re: wxSearchCtrl like Google Maps
ok,
in wxComboBox, is there a way to have the strings expanded without clicking the drop down menu?
my usage is:
1) user types a character, then combo expands with a string list returned from a search
2) user presses enter, then combo expands with the search
in wxComboBox, is there a way to have the strings expanded without clicking the drop down menu?
my usage is:
1) user types a character, then combo expands with a string list returned from a search
2) user presses enter, then combo expands with the search
Re: wxSearchCtrl like Google Maps
That's what it does.
Just try it out, it's only a few lines of code when you use a static list of items:
Just try it out, it's only a few lines of code when you use a static list of items:
Code: Select all
wxArrayString items;
items.Add( wxT("Ananas") );
items.Add( wxT("Apple") );
items.Add( wxT("Banana") );
items.Add( wxT("Batteship") );
items.Add( wxT("Cherry") );
items.Add( wxT("Coconut") );
m_combo_box = new wxComboBox( panel, ITEM_COMBO_ID, wxEmptyString, wxDefaultPosition, wxDefaultSize, items, wxTE_PROCESS_ENTER);
m_combo_box->AutoComplete( items );
Use the source, Luke!
Re: wxSearchCtrl like Google Maps
ok,
Popup() is the method that expands the list
Popup() is the method that expands the list
Re: wxSearchCtrl like Google Maps
that example works perfectly
but in my case , the combo is initially empty
I create it with
then when pressing enter
this all works fine, but I am not sure how to add the auto complete here
adding
causes the combo not to display anything
but in my case , the combo is initially empty
Code: Select all
wxArrayString m_results;
wxComboBox* m_combo;
Code: Select all
wxComboBox* combo = new wxComboBox(toolbar, ID_SEARCH_CTRL,
m_str_search, wxDefaultPosition, wxSize(400, -1),
m_results, wxTE_PROCESS_ENTER);
toolbar->AddControl(combo);
m_combo = combo;
then when pressing enter
Code: Select all
//m_results is filled
m_combo->Append(m_results);
m_combo->Popup();
adding
Code: Select all
m_combo->AutoComplete(m_results);
Re: wxSearchCtrl like Google Maps
Which platform and wxWidgets version are you using?
Maybe just a single wxTextCtrl is more suitable for your purpose than a wxComboBox.
That should not be necessary to let the autocomplete choices appear. As soon as you type "a" into the text field, the popup with "Ananas" and "Apple" should appear.Popup() is the method that expands the list
Maybe just a single wxTextCtrl is more suitable for your purpose than a wxComboBox.
Use the source, Luke!
Re: wxSearchCtrl like Google Maps
the autocomplete is working.
I want to call Popup() after the search so that it is visible immediately, just like Google maps does
I want to call Popup() after the search so that it is visible immediately, just like Google maps does
Code: Select all
wxArrayString items;
items.Add(wxT("Ananas"));
items.Add(wxT("Apple"));
items.Add(wxT("Banana"));
items.Add(wxT("Batteship"));
items.Add(wxT("Cherry"));
items.Add(wxT("Coconut"));
m_combo->Append(items);
m_combo->AutoComplete(items);
m_combo->Popup();