在QPixmap上渲染QGraphicsItem:聚合'QWidget w'类型不完整,无法定义
Render QGraphicsItem on QPixmap: aggregate 'QWidget w' has incomplete type and cannot be defined
我想在不绘制场景的情况下将项目绘制到 QPixmap 中......
我尝试过,基于这个:
void Item::itemPaint(QPainter *painter)
{
QStyleOptionGraphicsItem opt;
QWidget w;
paint(painter, &opt, &w); // also tried NULL
}
void Item::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
{
....
}
void caller()
{
QPainter* painter;
for(int i = 0; i< collectionView->scene()->items().size(); i++)
{
QGraphicsItem* qitem = collectionView->scene()->items().at(i);
Item* item = new Item(*(dynamic_cast<Item*>(qitem)));
QPixmap pItem(item->boundingRect().size().toSize());
pItem.fill(QColor(Qt::color0).rgb());
painter = new QPainter(&pItem);
painter->setRenderHint(QPainter::Antialiasing);
item->itemPaint(painter);
painter->end();
}
}
我得到
error: aggregate 'QStyleOptionGraphicsItem opt' has incomplete type and cannot be defined
error: aggregate 'QWidget w' has incomplete type and cannot be defined
如何使用项目的绘制方法将单个项目仅渲染到 QPixmap ?
我认为另一种方法是在项目矩形上创建另一个 QGraphicsView,然后渲染它,但我认为这会占用太多的开销......
#include <QWidget>
和#include <QStyleOptionGraphicsItem>
应该可以修复您遇到的编译错误。
相关文章:
- 有没有一种方法可以通过"typedef"为重新定义的基本类型定义特征和强制转换运算符
- 强枚举类型定义:Clang Bug 还是 C++11 标准不确定性?
- 列表参数的类型定义
- 使用模板化的键类型定义 std::map,该键类型基于作为参数接收的函数
- 关于 C++ 中的函数类型定义
- C++(和 ROS) - 包含与前向声明引用,设置默认值和类型定义
- 将使用/类型定义限制为类范围
- 模板类型定义?
- C++:模板类的类型定义
- 如何对命名空间限定类型进行类型定义?
- 此递归模板类型定义是否有效C++?
- 具有调整对齐方式的类型定义
- C++从抽象类型定义类成员
- 用于C++代码的 API 监视器类型定义 (XML)
- 如何将result_of与函数类型定义一起使用
- 在C++的适当类型定义位置
- 如何根据模板类型定义浮点常量?
- 如何为缺少预定义运算符而不扩展命名空间"std"的标准类型定义运算符>> (istream &, ...)?
- 参数化类的别名(或类型定义)内部类
- 如果我想从类型"T"定义元素的容器(来自 STL),那么"T"必须使用默认构造函数?