[Qt-interest] How to disable combo box list items?
Robert Hairgrove
evorgriahr at hispeed.ch
Mon Dec 29 21:49:24 CET 2008
J-P Nurmi wrote:
> On Mon, Dec 29, 2008 at 9:36 PM, Robert Hairgrove
> <evorgriahr at hispeed.ch> wrote:
>
> What would be the easiest way of graying out list items similar to when
> a menu item is disabled? I have a configuration dialog with stacked
> widgets selected by a combo box (a QComboBox created in QtDesigner).
>
> In this particular case, I am offering database support for a limited
> number of interfaces: MySQL, MSAccess, ODBC and SQLite. The idea would
> be to keep the same code base accross different platforms, but maybe
> disable MSAccess support on Linux.
>
> Looks like there is no built-in way to do this? I would really like to
> avoid subclassing the combo box, item delegates etc. if possible (LOTS
> of work involved there...).
>
>
> QComboBox uses QStandardItemModel by default. The following snippet
> would disable the current item:
>
> QStandardItemModel* model =
> qobject_cast<QStandardItemModel*>(comboBox->model());
> if (model) {
> QModelIndex index = model->index(comboBox->currentIndex(),
> comboBox->modelColumn(), comboBox->rootModelIndex());
> QStandardItem* item = model->itemFromIndex(index);
> if (item) {
> item->setEnabled(false);
> }
> }
>
> --
> J-P Nurmi
>
Yes, indeed ... that works wonderfully. Thank you! :)
More information about the Qt-interest-old
mailing list