Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;Qt:在QStyledItemDelegate::paint方法中设置活动小部件_C++_Qt - Fatal编程技术网

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

C++ C++;Qt:在QStyledItemDelegate::paint方法中设置活动小部件,c++,qt,C++,Qt,我想使用QStyledItemDelegate在treeviews子行中设置一个小部件。 小部件按预期显示,但不可单击。它似乎不是“活动的” 这是我的绘画方法: ProjectSpecificDelegate::ProjectSpecificDelegate(QObject *parent) : QStyledItemDelegate(parent) { } void ProjectSpecificDelegate::paint(QPainter *painter, const QS

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

这是我的绘画方法:

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);
    }
}
ProjectSpecificDelegate::ProjectSpecificDelegate(QObject*parent):
QStyledItemDelegate(父级)
{
}
void ProjectSpecificDelegate::paint(QPaint*painter,常量qStyleOption视图项和选项,常量QModelIndex和索引)常量
{
QStyledItemDelegate::paint(油漆工、选项、索引);
if(index.data(SpecialTreatmentsArchiv::ParentRowRol.toString()!=“parent”)
{
if(option.state&QStyle::state_选中)
{
painter->fillRect(option.rect,option.palete.highlight());
}
QPaintDevice*original_pdev_ptr=painter->device();
QList item_list=index.data(SpecialTreatmentsArchiv::ChildRowRole).value();
ProjectSpecificArchiv扩展窗口小部件(项目列表);
画师->结束();
展开_widget.render(painter->device(),QPoint(option.rect.x(),option.rect.y()),QRegion(0,0,option.rect.width(),option.rect.height()),QWidget::DrawChildren);
油漆工->开始(原件);
}
其他的
{
QStyledItemDelegate::paint(油漆工、选项、索引);
}
}

我的问题是:我必须更改什么才能与小部件交互?

您的小部件看起来像一个图像,因此您无法与它交互。我建议重写
QStyledItemDelegate::createEditor()
函数,该函数将返回您的
expand\u小部件
。感谢您的帮助。这似乎可行,但我的小部件只有在单击子行时才会出现。是否可以在每次展开父行时显示它?是否保留paint()和createEditor()函数的实现?Pain呈现委托,当节点处于编辑模式时,createEditor返回小部件进行交互。你需要把这两个概念结合起来。我可以在没有绘制功能的情况下显示小部件。当我展开父行并单击它时,我可以看到我的小部件。我不想编辑数据。我只是想要一个好看的方式来显示我的数据。我想要为每个子行创建我的小部件。但不仅仅是我点击它。有什么想法吗?