简体   繁体   中英

Is there anyway to lock or freeze qcombobox to prevent user to change index in qtcreator?

I am new at QtCreator and c++. I am trying to prevent user to change qcombobox index after choosing once. I tried to delete all items and after add only the choosen value but its very long way to do. I couldn't find any function to do this. Any ideas?

Locking a QComboBox while the user interacts with it is usually not a good idea in terms of user experience.

A QComboBox is, like any other QWidget , locked by disabling it using QWidget::setEnabled . This will also change its color (it is "grayed-out"), to signalize that the user cannot interact with it anymore.

You can connect to the QComboBox::currentIndexChanged signal to achieve your goal:

connect(my_combo_box, qOverload<int>(&QComboBox::currentIndexChanged), [my_combo_box]() {
    my_combo_box->setEnabled(false);
});

Note that the usage of qOverload requires C++14.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM