customize wxTextCtrl autocomplete - c++

I have a wxTextCtrl object and set it to be autocomplete
wxArrayString _myStringArray;
_myStringArray.push_back("abc");
_myStringArray.push_back("alpha");
_myStringArray.push_back("bnm");
_myTextCtrl->AutoComplete(_myStringArray);
I type char 'a' into it. And then a popup shown with a list of related/suggested strings (i.e "abc" and "alpha"). Now I press 'down arrow key' in order to select a string. The first time I press the button the "abc" string is selected. The second time I press the button the "alpha" string is selected.
The problem is changing the string selection by pressing UP and DOWN arrow keys doesn't change the text control value. I want the text control value to be updated when the selected string changed by pressing UP and DOWN arrow key.
I thought I could do that manually if I know the event name. So the question is: what is the event name (or event macro) of changing string selection from a popup in a wxTextCtrl by pressing UP and DOWN arrow key?
Thanks
update: I am succeded on capturing KEY DOWN event by subclassing wxTextCtrl and then add an event handler for EVT_KEY_DOWN event.
void TextCtrlChild::keyHandler(wxKeyEvent& event)
{
int _keyCode = event.GetKeyCode();
if(_keyCode == 315 || _keyCode == 317){ //if UP or DOWN arrow key is pressed
//TO DO: capture the highlighted string from the popup
}
event.Skip();
}
Now the question is how to capture the selected/highlighted string from the popup?

The way autocompletion works is dictated by the system UI conventions, so it doesn't look like a good idea to interfere with it. If you really want to have immediate selection, consider using another control, such as wxChoice, instead.

Related

SendDlgItemMessage CB_GETLBTEXT on DropDownList combo returns a single letter

I'm using the following code to retrieve the text of a combo dropdown list item.
char strText[255];
SendDlgItemMessage(hWnd,IDC_COMBO_VOICES, CB_GETLBTEXT,0, (LPARAM)strText);
std::string sTest = (strText);
I expected a longer string, but both strText and sTest only contain a single letter.
It is in fact that first letter of the combobox item text, so I can't be completely wrong, but I still don't get it right.
What am I missing here?
Make sure you tick the 'Has Strings' checkbox in the Combo Box's properties

Edit Win32 combo box items

I have a combo box with a list of names that are editable through a text box on the same form. How would I go about editing the items that are sitting in the combo box when the user changes the name in the text box? There doesn't seem to be any message to update the strings sitting inside the combo box.
Thanks,
Edit: this is the code thats called when the text changes
void txtNameChange(HWND hDlg)
{
if(SelectedIndex != -1)
{
wchar_t Name[255];
GetDlgItemText(hDlg, txtName, Name, 255);
//need to set the item text of an item at a certain index here
}
}
You cannot rename an item in place. You need to delete the item you wish to modify with the CB_DELETESTRING message, and then insert the new value with the CB_INSERTSTRING message.

How to find out which radio button chosen by the user

I have four radio buttons, the user must choose one of the four radio buttons.
The problem is each radio button has its own name differs from the other.
How to find out which radio button chosen by the user ?
Add the buttons into a GroupBox and use findChildren, after this you can use QButtonGroup or simply iterate through all Buttons list and check name of radiobutton. It is efficient way because it works with 4 button or 1000, you should write big code if you have many buttons.
void MainWindow::on_pushButton_15_clicked(){
QButtonGroup group;
QList<QRadioButton *> allButtons = ui->groupBox->findChildren<QRadioButton *>();
qDebug() <<allButtons.size();
for(int i = 0; i < allButtons.size(); ++i)
{
group.addButton(allButtons[i],i);
}
qDebug() << group.checkedId();
qDebug() << group.checkedButton();
}
You can use the 'isChecked()' command that all qt buttons support, and check each radio button. Or, you can connect a function to the 'toggled(bool isChecked)' signal, and use that to update a value indicating which of the four radio buttons is checked.
The numeric values of the four IDs should be continuous. Given that, call GetCheckedRadioButton to determine which one is selected.

Hide text in column as password dots in QtTableWidget

I have table (created by QTableWidget).
My table has 3 columns
# | user | pass
Text in user and in password is visible i.e "user", "password"
I want to hide text in pass like:
"********" < means "password"
In QLineEdit is good option called "echomode" but it is only for QLineEdit.
I can manually replace text for *, but how can i read this text later from a table (in class) ?
Better than ** will be dots. (like echomode -> password)
Regards
I would set the table item text to "*****", and store the real password as an item data with specific role. For example:
// Get the password item of first row
QTableWidgetItem *passwordItem = tableWidget->item(0, 2);
passwordItem->setText("*****");
passwordItem->setData(Qt::UserRole, "the_actual_password");
Extracting the actual password could be made in the similar way:
QString actualPassword = passwordItem->data(Qt::UserRole).toString();
You create a QStyledItemDelegate that you set on the column of passwords in the view (not the model, setItemDelegateForColumn()). When asked to create the editor (createEditor()) it should create a QLineEdit set to obscure the echo. You can have the delegate look at the value in another column before deciding whether to obscure the password.
http://www.qtcentre.org/threads/55315-How-can-i-have-echomode-in-QtableView-for-password-column
It's a bit old but I would like to warm it up, because it wasn't working that easily for me with Qt5.
The proper way to do this is to use a QStyledItemDelegate and override the paint method. But it seems so, that you've to paint on the widget stored in the option view (I looked into Qt's source).
QStyleOptionViewItem opt = option;
initStyleOption(&opt, index);
opt.widget->style()->drawItemText(painter, opt.rect, Qt::AlignLeft, opt.palette, true, "*****");
When I do not do it in this way I get a lot of strange side effects when table cell's selection changes.

How to check which item from menu was chosen? How to send int/wxstring with choosing menu item?

I've got menu in which i need to place dynamically few items( i don't know how many until app launch;-). It's not problem to put item in menu, and connect it`s event to some function. But i need to check which item from menu was chosen. Can i send int or wxString with click at menu item? How?
wxMenu *MyTaskBarIcon::CreatePopupMenu(){
wxMenu *menu = new wxMenu;
menu->Append(ITEM1, _("Item1"));
Connect(ITEM1,wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MyTaskBarIcon::Check));
menu->Append(ITEM2, _("Item2"));
Connect(ITEM2,wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MyTaskBarIcon::CheckMenu));
menu->AppendSeparator();
menu->Append(PU_EXIT, wxT("E&xit"));
}
void MyTaskBarIcon::Check(wxCommandEvent& event){
//How to send int/wxString to this method?
}
Any ideas?
How about assigning a range of IDs to this menu? Then when you append the items to the menu, you can increment the ID each time, so each item gets a unique ID. Then you create an event handler for each ID, and call a common handler with the ID as a parameter. Or, you could use
wxEvent::GetId()
If the strings vary at runtime then you will have to store the strings in an array, and recall them from there using the ID minus the start of the range ID as the index into the array.
Use GetString() to see what the user selected:
wxString GetString () const
Returns item string for a listbox or choice selection event.