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