PDA

View Full Version : need help .not able to understand.......



sh123
19th January 2009, 15:34
I got the program in which image gets rotated.But here the original image doesn't get displayed.Instead the image is displayed as zoomed & every pixel looks like a chip(i.e.IC).The following is the function which does zooming:


void MainWindow::PopulateScene()
{
scene = new QGraphicsScene;

QImage image(":/qt4logo.png");

// Populate scene
int xx = 0;
int nitems = 0;
for (int i = -11000; i < 11000; i += 110) {
++xx;
int yy = 0;
for (int j = -7000; j < 7000; j += 70) {
++yy;
qreal x = (i + 11000) / 22000.0;
qreal y = (j + 7000) / 14000.0;

QColor color(image.pixel(int(image.width() * x), int(image.height() * y)));
QGraphicsItem *item = new Chip(color, xx, yy);
item->setPos(QPointF(i, j));
scene->addItem(item);

++nitems;
}
}
}
This is from the program chip.The path is as follows:\Qt\4.4.3\demos\chip.
I want to know how the original image can be displayed instead of zoomed one.Please help

wysota
20th January 2009, 02:50
Definitely not like this :)

Try this instead:

QGraphicsView *gv = new QGraphicsView;
gv->setScene(new QGraphicsScene);
gv->scene()->addPixmap(QPixmap("somepixmap.png"));
gv->show();
And next time please try to find some code snippet or documentation paragraph that is at least somewhat similar to your problem.