PDA

View Full Version : can the image be displayed as it is in chips prog..



sh123
3rd February 2009, 11:45
Can somebody please tell me if the image can be displayed as it is in chips program.Here image is displayed as chips instead of the original image.After doing zoom-out the original image appears.The chip program's path is:\Qt\4.4.3\demos\chip.The code is :
void MainWindow::populateScene()
{
scene = new QGraphicsScene;

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

// Populate scene
int xx = 0;
int nitems = 0;
for ([color=blue]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;
}
}
}

jacek
4th February 2009, 01:55
I'm not sure if I understand you correctly. Do you want to achieve the same effect as in chips demo? If yes, then just copy the demo code.

sh123
4th February 2009, 06:25
Thanks for responding.No i don't want to achieve the same effect as in chips demo.When we run the chips demo we see the chips(that is,the image in the zoomed form).I want that the image be displayed as it is instead of zoomed one.

jacek
4th February 2009, 20:28
So you just want to display an image as a single item?

sh123
5th February 2009, 09:21
yes I want to display image as a single item.

aamer4yu
5th February 2009, 09:30
Then have a look at QLabel::setPixmap and if u want to use graphics view, have a look at QGraphicsPixmapItem

Hope it helps :)

jacek
5th February 2009, 22:07
yes I want to display image as a single item.
Then use QGraphicsPixmapItem as aamer4yu said. Chips demo doesn't show any pixmaps --- it shows only chips. ;)

sh123
6th February 2009, 14:36
Thanks very much for the help...I have one more query that I have used Q3ScrollView & displayed an image in it using QLabel.I want to scroll the image.so I tried using QSlider.the QSlider is coming behind the image(that is,QLabel).

jacek
6th February 2009, 17:57
I have one more query that I have used Q3ScrollView & displayed an image in it using QLabel.
Use QScrollArea instead and you don't need QSlider, because scroll area/view already has scroll bars. You just have to set it up the right way. There is an example in the docs.

sh123
7th February 2009, 06:07
Thanks again.I saw the documentation & used the following code:


QLabel *imageLabel = new QLabel;
QImage image("happyguy.png");
imageLabel->setPixmap(QPixmap::fromImage(image));

scrollArea = new QScrollArea;
scrollArea->setBackgroundRole(QPalette::Dark);
scrollArea->setWidget(imageLabel);
Compiler gave the following error :
canvas.cpp:372: warning: statement has no effect
canvas.cpp:442: error: `scrollArea' undeclared (first use this function)
canvas.cpp:442: error: (Each undeclared identifier is reported only once for eac
h function it appears in.)
mingw32-make[1]: *** [tmp/obj/debug_shared/canvas.o] Error 1
mingw32-make[1]: Leaving directory `D:/Qt/4.4.3/examples/graphicsview/portedcanv
as'
mingw32-make: *** [debug-all] Error 2

aamer4yu
7th February 2009, 07:24
U dont seem to have declared scrollArea
Declare it as - QScrollArea * scrollArea = new QScrollArea

sh123
7th February 2009, 08:15
Yes now I declared scrollArea.Compiler is not giving error now.but in the output neither scrollarea is seen nor label(image) is seen.