PDA

View Full Version : QGraphicsScene Low Image Quality



nemmartins
30th March 2010, 12:21
Hi all,

we are porting our software to QT. In our software we have a view that shows an image, and the user can drag objects from the toolbar to the page.

The image is always a jpeg, with high resolution, so when we see it on screen is always shrinked. The problem is that the image when shrinked has very poor quality, when comparing to our previous Windows platform using GDI+.

We tried all the render hints available, but the quality is still very poor. I was expecting that for a 3000$ license (not paid, we are testing before), at least the resize algorithms would be some good. In GDI+ we never had to do extra work, just set the render hints, and we get good shrinked image quality!

What do we need to do to have a good shrink image quality?

The JPEG image object is a subclassed QGraphicsRectItem. We tried QImage and QPixmap for drawing the image, but results are the same! The images are drawed inside the paint event in our subclassed QGraphicsRectItem.

void CCanvasPageImage::paint( QPainter *p, const QStyleOptionGraphicsItem *option, QWidget * widget)
{
p->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing | QPainter::HighQualityAntialiasing | QPainter::NonCosmeticDefaultPen, true);

p->drawImage( option->exposedRect, m_image, option->exposedRect, Qt::OrderedAlphaDither );
// p->drawPixmap( option->exposedRect, m_pixmap, option->exposedRect );
}

Any help would be appreciatted here...

Thanks

pherthyl
30th March 2010, 19:22
Couple things:
Use drawPixmap. QImage is optimized for editing, and QPixmap is optimized for display. So if you are painting often, then do it with QPixmap and drawPixmap (drawImage will internally convert to a QPixmap which is slow).

Your drawing code seems alright. You could try setting the SmoothPixmapTransform render hint on the view, although that shouldn't make a difference.

Are you drawing your image in full and unscaled, scaled, or clipped? Because if you're scaling your image and are using something like QPixmap::scaled(), then you have to pass it the Qt::SmoothTransformation transformation mode. Post the code where you load your pixmap/image.

wysota
30th March 2010, 20:19
I was expecting that for a 3000$ license (not paid, we are testing before), at least the resize algorithms would be some good. In GDI+ we never had to do extra work, just set the render hints, and we get good shrinked image quality!

$3000 have nothing to do with image scaling. Algorithms for image scaling are well known and are free of charge. It would be silly to implement something bad if at the same price you can have something good so assuming something like that could be considered silly as well.