1
votes

I have a QGraphicsPixmapItem in a QGraphicsScene which I then zoom into and rotate in a QGraphicsView. Everything works great if there is no rotation or if I don't zoom in too far, however when I am zoomed way in (pixels are very visible) and rotate around strange things occur. Some of the time the image looks as I would expect, some of time the pixmap disappears (partially or completely), and some of the time horizontal gradients appear on the image (they remain horizontal even while the image rotates).

image with gradientsenter image description here

The first image is of a chart (there should be no color gradients) with a separate grid (collection of lines) imposed over it. The second image comes from my minimal example (below) and shows the pixmap partially missing (the shot is far away from the edge of the pixmap).

The following is a simple example which demonstrates most of what I am seeing.

#ifndef VIEW_H
#define VIEW_H

#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsPixmapItem>
#include <QWheelEvent>
#include <QKeyEvent>

class View : public QGraphicsView
{
  Q_OBJECT
public:
  explicit View(QWidget *parent = 0) :
    QGraphicsView(parent)
  {
    setDragMode(QGraphicsView::ScrollHandDrag);

    QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem(QPixmap(":/images/chart.png"));
    pixmapItem->setTransformationMode(Qt::SmoothTransformation);

    QGraphicsScene *scene = new QGraphicsScene();
    scene->addItem(pixmapItem);
    setScene(scene);
  }

protected Q_SLOTS:
  void wheelEvent(QWheelEvent *event)
  {
    if(event->delta() > 0)
      scale(1.25, 1.25);
    else
      scale(0.8, 0.8);
  }

  void keyPressEvent(QKeyEvent *event)
  {
    if(event->key() == Qt::Key_Left)
      rotate(1);
    else if(event->key() == Qt::Key_Right)
      rotate(-1);
  }
};

#endif // VIEW_H

The other files surrounding this are a resource file with the image, a QMainWindow class that holds View in its ui, and a main that puts executes the main window class, all of which are available in a Github project.

To reproduce zoom in with the mouse scroll wheel and rotate with the arrow keys (you can also pan with the mouse). If you zoom in far enough and rotate, the pixmap will disappear (partially or completely) at some angles. I have been unable to recreate the gradients in this example yet, but my suspicion is that they are just another manifestation of the same problem.

I have tried setting the transformation to SmoothTransformation and setting the renderHint to both Antialiasing and HighQualityAntialiasing but neither has had a major effect (the antialasing does smooth out the jaggies at high zooms). Additionally I have tried toggeling many flags in QGraphicView, QGraphicsScene related drawing. Does anyone know why this could be happening or what I can try to address it?

I have seen this problem in both Qt 4.8.2 and Qt 5.5.1 which I downloaded on 10/18/16 as the current stable version of Qt.

1
what does the original image look like?xaxxon
As it stands, whilst you have a legitimate problem, we can only guess as to what is causing the issue. Providing an MCVE would greatly improve the question.TheDarkKnight
I just posted a MCVE, it includes the png.Chris
The "M" stands for minimal. That thing should be less than 150 lines of code, fit in a single file, and be included in the question itself. You should also try your code on the most recent Qt and check if it behaves any different; you could then bisect to check where it got fixed.Kuba hasn't forgotten Monica
Same behavior in latest Qt. I'll try to trim down my example more.Chris

1 Answers

0
votes

It appears that this may have something to do with a limitation of x11. Basically once a large enough zoom is hit the max size value is hit.

I'm still not entirely sure why rotation appears to effect things but as a conjecture it could be because it is related to the size of the bounding rect of the image which will vary at different angles. The gradients I have seen are also odd as well as the image only partially disappearing, but it seems likely that they are all related and this is another manifestation.