Chris Chris - 1 year ago 245
C++ Question

Strange drawing behavior for QGraphicsPixmapItem in a zoomed and rotated in QGraphicsScene

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
explicit View(QWidget *parent = 0) :

QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem(QPixmap(":/images/chart.png"));

QGraphicsScene *scene = new QGraphicsScene();

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

void keyPressEvent(QKeyEvent *event)
if(event->key() == Qt::Key_Left)
else if(event->key() == Qt::Key_Right)

#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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download