QTreeView与setIndexWidget [英] QTreeView vs setIndexWidget

查看:1449
本文介绍了QTreeView与setIndexWidget的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将QStandardItemModel与QStandardItem一起使用.

I am using QStandardItemModel with QStandardItem's.

我不想编写自己的模型和任何委托.

I don't want to write my own model and any delegates.

我只想在第二列中使用带有QComboBox的复选框树...

I just want to have tree of checkboxes with QComboBox'es in second column...

m_model->setColumnCount(2);
for (int i = 0; i < sectionCount; i++)
{
    QStandardItem * section = new QStandardItem(tr("Section %1").arg(i+1));
    section->setCheckable(true);
    section->setCheckState(Qt::Checked);

    for (int j = 0; j < itemsCount; j++)
    {
        QStandardItem * item = new QStandardItem(tr("Item %1").arg(j+1));
        item->setCheckable(true);
        item->setCheckState(Qt::Checked);

        QStandardItem * item2 = new QStandardItem("xxx");

        section->appendRow(QList<QStandardItem*>() << item << item2);

        QComboBox * combo = new QComboBox();
        QModelIndex index = m_model->index(j, 1, );

        // HERE i have index = {-1;-1}

        ui->treeView_options->setIndexWidget(index, combo);
    }
    m_model->appendRow(section);
}

是否可以通过这种方式使用setIndexWidget?

Is it possible to use setIndexWidget this way?

更新:

第二栏中没有QComboBox ...为什么?

I have no QComboBox in second column... Why?

推荐答案

不,不起作用:

此功能仅应用于在与数据项相对应的可见区域内显示静态内容.如果要显示自定义动态内容或实现自定义编辑器小部件,请改用QItemDelegate子类.

This function should only be used to display static content within the visible area corresponding to an item of data. If you want to display custom dynamic content or implement a custom editor widget, subclass QItemDelegate instead.

这篇关于QTreeView与setIndexWidget的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆