PDA

View Full Version : QGrahpicsScene transform is very slow under Linux



yazwas
16th March 2010, 14:16
Good day everyone

I wrote a simple QGraphicsView, QGraphicsScene application that loads image file and add it to QGraphicsPixmapItem, I then can create a selection rectangle using rubber band.

my main problem is that this works fine under Windows, but under Linux I have 2 situations
1- if the scene is not zoomed (100%) zoom, it works fine, and I can select the rectangle very fast, and scroll, ..etc very fast
2- if the scene is zoomed other than 100% (less or more), this becomes very very slow.

I have attached the full source code for anynoe who likes to give it a try, please feel free to tell me what you think, and what could be the problem for this issue.

The zooming is done using the transform function

here is the code for it


void SourceScene::transform(qreal zoomFactor, qreal angle)
{
if (!m_imageItem)
return;

// we erase selection rect if it exists.
removeSelectionRect();

// we compute image center.
qreal imageCenterX = m_imageItem->x()+ m_imageItem->boundingRect().width()/2;
qreal imageCenterY = m_imageItem->y()+ m_imageItem->boundingRect().height()/2;
// we apply the transformation zoom + rotation.
m_imageItem->setTransform(QTransform().translate(imageCenterX, imageCenterY).rotate(angle).scale(zoomFactor, zoomFactor).translate(-imageCenterX, -imageCenterY));
}

here is the paint function for the seletion rectangle item (QGraphicsPolygonItem item)


void SelectionRectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
static int i=1;
qDebug("%d SelectionRectItem::paint()", i++);
QColor color = Qt::red;

QPen pen(Qt::NoPen);
//pen.setColor(color);
//pen.setWidth(2);
painter->setPen(pen);

QBrush brush;
brush.setStyle(Qt::Dense7Pattern);

brush.setColor(color);
painter->setBrush(brush);


QPolygon ply(rg, true);
setPolygon(ply);
painter->drawPolygon(polygon(), fillRule());
//scene()->update(sceneBoundingRect());
}

I'm not sure if this is the problem or something else

please if anyone can look at the code, and check what could be the problem, or if anyone has any ideas on how to fix this issue

To reproduce the effect please choose a pic image over 1 mb size, and then try to zoom in or zoom out, it does not matter, the creation of the selection rectangle will be slow either way

Best regards

yazwas
16th March 2010, 22:05
Hello

I think I found the problem, its because of this line


void SourceScene::transform(qreal zoomFactor, qreal angle)
{
if (!m_imageItem)
return;

// we compute image center.
qreal imageCenterX = m_imageItem->x()+ m_imageItem->boundingRect().width()/2;
qreal imageCenterY = m_imageItem->y()+ m_imageItem->boundingRect().height()/2;

///THIS IS THE LINE THAT CAUSES THE ISSUE, THE imageitem is causing the problem and making it very slow.
m_imageItem->setTransform(QTransform().translate(imageCenterX, imageCenterY).rotate(angle).scale(zoomFactor, zoomFactor).translate(-imageCenterX, -imageCenterY));
}

The definition of the imageitem is below

#include <QGraphicsPixmapItem>


class ImageItem : public QGraphicsPixmapItem
{
public:
ImageItem(const QPixmap & pixmap, QGraphicsItem * parent = 0); ///< ctor

virtual ~ImageItem(); ///< dtor

QPixmap getImageCutoutPixmap(const QRectF & selectionRect) const; //does something later on, but nothing with the transformation of the page

};

ImageItem::ImageItem(const QPixmap & pixmap, QGraphicsItem * parent) :
QGraphicsPixmapItem(pixmap, parent)
{
setZValue(0.5);
setCursor(QCursor(Qt::CrossCursor));
}


its very basic, and I dont know what is the problem with it is. is this a LINUX issue? it only happens in Linux, and I'm not sure what could be the problem.

ANY COMMENT IS MORE THAN WELCOME

Best regards

yazwas
17th March 2010, 11:57
Hello Everyone,

The problem is only if I dont have the pixmapitem in its original size. i.e. I call the setTransform function when I do zoom in/out. if the zoom = 1, it works extremley well even if the page is very large. what could be the problem?

guys, any response, anyone thinks it cant be solved, just tell me, any long shot suggestions
anyone :crying: hellllp

yazwas
19th March 2010, 18:22
Hello all

if I use -graphicssystem raster as parameter, it works fine
i.e.
./myapp -graphicssystem raster