[Qt-interest] how to show large image fastly?

wanneng yangguosdxl at gmail.com
Wed Aug 18 08:35:45 CEST 2010


My code like following, and the image is 125KB, format is png. it is 
slow when show the picture. and more bad is that I may be use the larger 
picture, it may be 1MB. So does anyone know how to show large image 
fastly? thank you.

Map::Map(QWidget* parent) : QWidget(parent)
{
     isShow = true;

     worldMap = new QPixmap(":/images/map.png", "png");
     qreal factor = this->width()/worldMap->width();
     qDebug("worldMap.width, height: %d, %d", worldMap->width(), 
worldMap->height());

     //scene = new QGraphicsScene(0, 0, worldMap->width(), 
worldMap->height());
     scene = new QGraphicsScene(0, 0, 400, 300);
     scene->setBackgroundBrush(QColor(255, 255, 238));

     /* add map to scene */
     mapItem = scene->addPixmap(*worldMap);
     qDebug() << "mapItem boundingRect" << mapItem->boundingRect();
     mapItem->setFlags(QGraphicsItem::ItemIsMovable);
     //mapItem->setTransformationMode(Qt::FastTransformation);
     //mapItem->setCacheMode(QGraphicsItem::ItemCoordinateCache);
     // this cache mode make drag the picture fast
     mapItem->setCacheMode(QGraphicsItem::DeviceCoordinateCache);

     /* add station node to scene */
     drawStationNode();

     view = new MapView(this);
     view->setScene(scene);

     // let the view fit the widget automatically
     QVBoxLayout* vLayout = new QVBoxLayout;
     vLayout->addWidget(view);
     setLayout(vLayout);

     createActions();

     //slotFitWidget();
     updateAct();
}




More information about the Qt-interest-old mailing list