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
如何从QItemDelegate获取对Qt::DecorationRole的访问权?_Qt_Qitemdelegate - Fatal编程技术网

如何从QItemDelegate获取对Qt::DecorationRole的访问权?

如何从QItemDelegate获取对Qt::DecorationRole的访问权?,qt,qitemdelegate,Qt,Qitemdelegate,我需要自定义组合框,其中包含“一个矩形调色板,后跟一个文本描述”格式的文本 Iam为QComboBox使用自定义itemdelegate。 在组合框中,我检查项目的状态,并根据我的要求进行喷漆,如 if(option.state & QStyle::State_Selected) { painter->save(); QRect r = option.rect; QRect textRect =

我需要自定义组合框,其中包含“一个矩形调色板,后跟一个文本描述”格式的文本

Iam为QComboBox使用自定义itemdelegate。 在组合框中,我检查项目的状态,并根据我的要求进行喷漆,如

if(option.state & QStyle::State_Selected)
        {
            painter->save();
            QRect r = option.rect;
            QRect textRect = r;
        textRect.setX(r.x() + 8);

        textRect.setWidth(r.width() - 10);

        textRect.setY(r.y() -3);
        textRect.setHeight(r.height() +2);
        painter->drawText(textRect.left(), textRect.top() , textRect.width(), textRect.height()  ,
        flags, currText, &r);
             painter->restore();
} else {
          ...
}
现在,我想检查角色是否是装饰性角色,如果是,那么我必须添加pixmap,并将其与项目定位在相同的位置,就像我在绘制功能中对所选项目所做的一样

我找不到如何画一个具有装饰作用的物品(带文字的图像)

如何在ItemDelegate中绘制此文本?
这是我的实际要求

您在绘画方面有什么具体问题?我不清楚你在问什么。您可以使用
index.data(Qt::DecorationRole)获取数据我更新了我的答案..这并不能真正回答你的问题,但是你不能只使用QComboxes可用的图标功能吗?