qt - remove items from QComboBox from ui -
i trying tweak ui of qcombobox in way user can remove items drop down list (without first selecting them).
the background using qcombobox indicate data file open right now. using cache opened files. user able remove entries not want have listed anymore. either hitting delete key, or context menu, or whatever straightforward implement. not want rely on selecting item first. similar behavior can found in firefox, old cached suggestions entry filed can deleted.
i considering subclassing list view used qcombobox, however, did not find enough documentation me started.
i grateful hints , suggestions. using pyqt, have no problems c++ samples.
i solved problem using code installeventfilter documentation.
//must in header, otherwise moc gets confused missing vtable class deletehighlighteditemwhenshiftdelpressedeventfilter : public qobject { q_object protected: bool eventfilter(qobject *obj, qevent *event); }; bool deletehighlighteditemwhenshiftdelpressedeventfilter::eventfilter(qobject *obj, qevent *event) { if (event->type() == qevent::keypress) { qkeyevent *keyevent = static_cast<qkeyevent *>(event); if (keyevent->key() == qt::key::key_delete && keyevent->modifiers() == qt::shiftmodifier) { auto combobox = dynamic_cast<qcombobox *>(obj); if (combobox){ combobox->removeitem(combobox->currentindex()); return true; } } } // standard event processing return qobject::eventfilter(obj, event); } myqcombobox->installeventfilter(new deletehighlighteditemwhenshiftdelpressedeventfilter);
Comments
Post a Comment