C ++ Qt:在QStyledItemDelegate :: paint方法中设置一个活动的小部件

时间:2013-12-16 09:25:30

标签: c++ qt

我想使用QStyledItemDelegate在treeviews子行中设置一个小部件。 窗口小部件按预期显示但不可点击。似乎它不是“活跃的”。

enter image description here

这是我的绘画方法:

ProjectSpecificDelegate::ProjectSpecificDelegate(QObject *parent) :
    QStyledItemDelegate(parent)
{
}

void ProjectSpecificDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    QStyledItemDelegate::paint(painter, option, index);

    if(index.data(SpecialTreatmentsArchiv::ParentRowRol).toString() != "parent")
    {
        if (option.state & QStyle::State_Selected)
        {
            painter->fillRect(option.rect, option.palette.highlight());
        }

        QPaintDevice* original_pdev_ptr = painter->device();
        QList<ProjectSpecificArchivItem> item_list = index.data(SpecialTreatmentsArchiv::ChildRowRole).value<QList<ProjectSpecificArchivItem> >();

        ProjectSpecificArchiv expand_widget(item_list);

        painter->end();

        expand_widget.render(painter->device(), QPoint(option.rect.x(), option.rect.y()), QRegion(0, 0, option.rect.width(), option.rect.height()), QWidget::DrawChildren);

        painter->begin(original_pdev_ptr);
    }
    else
    {
        QStyledItemDelegate::paint(painter, option, index);
    }
}

我的问题是:我需要更改哪些内容才能与窗口小部件进行交互?

0 个答案:

没有答案