【问题标题】:Render QGraphicsItem on QPixmap: aggregate 'QWidget w' has incomplete type and cannot be defined在 QPixmap 上渲染 QGraphicsItem:聚合“QWidget w”类型不完整,无法定义
【发布时间】:2015-07-03 06:10:55
【问题描述】:

我想在不绘制场景的情况下将项目绘制到 QPixmap...

我试过了,基于this

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 可能会修复您遇到的编译错误。
  • 您可能还需要#include
  • 感谢没有更多的错误! (就在我用 update() 的调用替换了油漆时):-)
  • 请回答...

标签: c++ image qt qgraphicsitem qpainter


【解决方案1】:

#include &lt;QWidget&gt;#include &lt;QStyleOptionGraphicsItem&gt; 应该可以修复您遇到的编译错误。

【讨论】:

    猜你喜欢
    • 2014-05-20
    • 2021-06-24
    • 2020-02-21
    • 1970-01-01
    • 2020-11-25
    • 2013-07-21
    • 2012-07-29
    • 1970-01-01
    相关资源
    最近更新 更多