Hi,
"m_pCParameter" is a pointer to own class. This class contains a QList that is a list of possibilities that is used to fill the combo. Then I let the user choose one of this elements or to write a different text.
The possibilities are saved untranslated on the QList possibilitites and translated when are inserted to the combo, but when the user selects an item, the internal object needs to save the untranslated text.
So in "on_TextComboBox_textChanged(const QString &qText)" slot I use this code:
[LEFT
]ParametreTextWidget
::on_TextComboBox_textChanged(const QString &qText
) {
int iIndex = ui.TextComboBox->findText(qText,Qt::MatchFixedString | Qt::MatchCaseSensitive);
if (iIndex != -1)
{
if (!qList.empty())
{
QString qOriginalText
= qList.
at(iIndex
);
m_pCParameter->setText(qOriginalText);
}
else
{
m_pCParameter->setText(qText);
}
}
else
{
ui.[COLOR=#009900]TextComboBox[/COLOR]->setCompleter[COLOR=#000000]([/COLOR][COLOR=#0000dd]0[/COLOR][COLOR=#000000])[/COLOR];
ui.[COLOR=#009900]TextComboBox[/COLOR]->setEditable[COLOR=#000000]([/COLOR][COLOR=#0000ff]false[/COLOR][COLOR=#000000])[/COLOR]; [COLOR=#ff0000]//To not let the combo emit "textChanged"[/COLOR]
ui.[COLOR=#009900]TextComboBox[/COLOR]->clear[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR]; [COLOR=#ff0000]//Fill the combo with the list elements[/COLOR]
[COLOR=#0000ff]if[/COLOR] [COLOR=#000000]([/COLOR]!qLList.[COLOR=#009900]isEmpty[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000])[/COLOR]
[COLOR=#0000ff]for[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#0000ff]int[/COLOR] i = [COLOR=#0000dd]0[/COLOR]; i < qLList.[COLOR=#009900]size[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR]; ++i[COLOR=#000000])[/COLOR]
ui.[COLOR=#009900]TextComboBox[/COLOR]->addItem[COLOR=#000000]([/COLOR][URL="http://doc.trolltech.com/latest/QObject.html"]QObject[/URL]::[COLOR=#009900]tr[/COLOR][COLOR=#000000]([/COLOR]qLList.[COLOR=#009900]at[/COLOR][COLOR=#000000]([/COLOR]i[COLOR=#000000])[/COLOR].[COLOR=#009900]toAscii[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR].[COLOR=#009900]data[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000])[/COLOR];[COLOR=#ff0000] //Adding the text written by hand on the combo[/COLOR]
ui.[COLOR=#009900]TextComboBox[/COLOR]->addItem[COLOR=#000000]([/COLOR]qText[COLOR=#000000])[/COLOR];
[COLOR=#0000ff]if[/COLOR] [COLOR=#000000]([/COLOR]m_pCParameter->isEditable[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000])[/COLOR]
ui.[COLOR=#009900]TextComboBox[/COLOR]->setEditable[COLOR=#000000]([/COLOR][COLOR=#0000ff]true[/COLOR][COLOR=#000000])[/COLOR];
[/LEFT]
[LEFT]ParametreTextWidget::on_TextComboBox_textChanged(const QString &qText)
{
int iIndex = ui.TextComboBox->findText(qText,Qt::MatchFixedString | Qt::MatchCaseSensitive);
if (iIndex != -1)
{
QStringList qList = m_pCParameter->getList();
if (!qList.empty())
{
QString qOriginalText = qList.at(iIndex);
m_pCParameter->setText(qOriginalText);
}
else
{
m_pCParameter->setText(qText);
}
}
else
{
ui.[COLOR=#009900]TextComboBox[/COLOR]->setCompleter[COLOR=#000000]([/COLOR][COLOR=#0000dd]0[/COLOR][COLOR=#000000])[/COLOR];
ui.[COLOR=#009900]TextComboBox[/COLOR]->setEditable[COLOR=#000000]([/COLOR][COLOR=#0000ff]false[/COLOR][COLOR=#000000])[/COLOR]; [COLOR=#ff0000]//To not let the combo emit "textChanged"[/COLOR]
ui.[COLOR=#009900]TextComboBox[/COLOR]->clear[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR]; [COLOR=#ff0000]//Fill the combo with the list elements[/COLOR]
[COLOR=#0000ff]if[/COLOR] [COLOR=#000000]([/COLOR]!qLList.[COLOR=#009900]isEmpty[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000])[/COLOR]
[COLOR=#0000ff]for[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#0000ff]int[/COLOR] i = [COLOR=#0000dd]0[/COLOR]; i < qLList.[COLOR=#009900]size[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR]; ++i[COLOR=#000000])[/COLOR]
ui.[COLOR=#009900]TextComboBox[/COLOR]->addItem[COLOR=#000000]([/COLOR][URL="http://doc.trolltech.com/latest/QObject.html"]QObject[/URL]::[COLOR=#009900]tr[/COLOR][COLOR=#000000]([/COLOR]qLList.[COLOR=#009900]at[/COLOR][COLOR=#000000]([/COLOR]i[COLOR=#000000])[/COLOR].[COLOR=#009900]toAscii[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR].[COLOR=#009900]data[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000])[/COLOR];[COLOR=#ff0000] //Adding the text written by hand on the combo[/COLOR]
ui.[COLOR=#009900]TextComboBox[/COLOR]->addItem[COLOR=#000000]([/COLOR]qText[COLOR=#000000])[/COLOR];
[COLOR=#0000ff]if[/COLOR] [COLOR=#000000]([/COLOR]m_pCParameter->isEditable[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000])[/COLOR]
ui.[COLOR=#009900]TextComboBox[/COLOR]->setEditable[COLOR=#000000]([/COLOR][COLOR=#0000ff]true[/COLOR][COLOR=#000000])[/COLOR];
[/LEFT]
To copy to clipboard, switch view to plain text mode
What I try to do if the item is handwritten(not exist on the possibility list) is to insert it as a item and save it to internal object.
Thanks,
Bookmarks