Separate display text for Selected Item for QComboBox
-
In a
QComboBox
I have a set ofQString
. The standard behavior is that whatever entry is selected gets displayed at top (QLineEdit
). However my need is to display a modified version of the selected text in the line edit without changing the text in the drop down list. How can I go about achieving this?e.g. If the list has { "a", "b", "c" }, selecting "a" , the line edit should contain "a-1".
-
@ajaxcrypto Using http://doc.qt.io/qt-5/qcombobox.html#lineEdit you can get the line edit and then change its text using http://doc.qt.io/qt-5/qlineedit.html#text-prop
-
@ajaxcrypto
Hi,Once you select item, activated(int index) signal will be emitted connect the signal to some slot.
// in slot do like this
void onActivated(int index)
{
QString LineEditStr =ComboBox.itemText(index).append("-").append(QString::number(index+1));LineEdit.setText(LineEditStr);
}
-
Thank you for pointing me in the right direction. I styled the Line edit accordingly and displaying a modified selected item text.