在Qt Combobox中禁用项目 [英] Disable Item in Qt Combobox
本文介绍了在Qt Combobox中禁用项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我找不到一个标准的方法来禁用Qt组合框中的单个项目。
I can't find a standard way to disable an individual item in a Qt combo box. Is there a facility to do this in Qt that I am missing?
推荐答案
取自在这里:
// Get the index of the value to disable
QModelIndex index = ui.comboBox->model()->index(1, 0);
// This is the effective 'disable' flag
QVariant v(0);
// the magic
ui.comboBox->model()->setData(index, v, Qt::UserRole - 1);
要再次启用:
QVariant v(1 | 32);
使用的模型将标志
Qt :: UserRole - 1
- 这就是这段代码的工作原理。它不是一个通用的解决方案,可以使用任意模型。
The model used maps the flags
word to Qt::UserRole - 1
-- that's what makes this code work. It's not a generic solution that would work with an arbitrary model.
这篇关于在Qt Combobox中禁用项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文