8

我重新实现了QGraphicsView以使用鼠标滚轮事件缩放场景。场景包含几个QGraphicsPixmapItem。轮子事件调用QGraphicsView::scale(qreal sx, qreal sy)

除了渲染,一切都完美无缺。当我缩小(场景变小)时,出现了锯齿。我尝试在重新实现的QGraphicsView构造函数中设置渲染提示如下:

ImageViewer::ImageViewer(QWidget * parent) :
  QGraphicsView(parent)
{
   setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::HighQualityAntialiasing);
}

我仍然看到这些文物。我怎样才能摆脱这个?

4

2 回答 2

8

请参阅我对这个问题的评论。

基本上你必须调用你想要应用抗锯齿setTransformationMode(Qt::SmoothTransformation)的s 。QGraphicsPixmapItem

调用setRenderHints视图对我也不起作用。

于 2013-08-18T20:39:30.190 回答
0

只有在使用画家之前设置了渲染提示,才会应用渲染提示。这里有一个片段:

QGraphicsPixmapItem *
drawGraphicsPixmapItem(const QRectF &rect)
{
    auto pixmap = new QPixmap(rect.size().toSize());
    pixmap->fill("lightGrey");

    auto painter = new QPainter(pixmap);
    // set render hints bevor drawing with painter
    painter->setRenderHints(QPainter::Antialiasing);

    QPen pen;
    pen.setColor("black");
    pen.setWidth(3);
    painter->setPen(pen);
    QRectF rectT = rect;
    rectT.adjust(pen.widthF()/2,pen.widthF()/2,-pen.widthF()/2,-pen.widthF()/2);

    QPainterPath circlePath;
    circlePath.addEllipse(rectT);
    circlePath.closeSubpath();
    painter->fillPath(circlePath,QBrush("green"));
    painter->drawPath(circlePath);
    auto pixmapItem = new QGraphicsPixmapItem(*pixmap);
    pixmapItem->setCacheMode(
             QGraphicsItem::CacheMode::DeviceCoordinateCache,
             pixmap->size() );
    return pixmapItem;
}
于 2018-07-16T11:54:37.350 回答