2
votes

I am using a QGraphicsScene and QGraphicsView to display a QGraphicsPixmapItem.

Whenever i rotate the item by anything but 90, 180, 270 degree the texture is displayed in extremly low quality. Image 1 shows the original texture (0° rotation) the 2 shows the item rotated by 45°.

I use the following code to display and rotate the item:

QGraphicsPixmapItem *item = new QGraphicsPixmapItem(QPixmap("button.png"));
scene->addItem(item);

item->setTransformOriginPoint(70, 70); // button.png is 140px x 140px
item->setRotation(45);

Using

view->setRenderHints(QPainter::Antialiasing);

or

view->setRenderHints(QPainter::SmoothPixmapTransform);

does not make a difference.

Is there any way to get a higher quality texture ?

Original45degree

1

1 Answers

1
votes

I had the same problem. The only way I found to fix this, was to reimplement the QGraphicsItem::paint() and apply the flags QPainter::Antialiasing | QPainter::SmoothPixmapTransform to the painter.

Like this:

void Rocket::paint(QPainter *painter,
                   const QStyleOptionGraphicsItem *option,
                   QWidget *widget)
{
  painter->setRenderHints( QPainter::Antialiasing | QPainter::SmoothPixmapTransform );
  painter->drawPixmap( boundingRect().topLeft(), myOriginalPixmap );
}