PDA

View Full Version : Regarding displaying image in grid.



prajna
20th February 2009, 10:35
I am trying to display the images in the grid using the below code.
I am able to get the first image.But second image won't come .


QGridLayout *grid = new QGridLayout();

//grid->setColumnMinimumWidth(2,30);
imageLabel = new QLabel;
imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
imageLabel->setScaledContents(true);
setCentralWidget(imageLabel);
resize(100,100);
QString NextImagepath = "c:\\Data\\Images\\Pictures\\error.bmp";
QPixmap Nextimage(NextImagepath);
imageLabel->setPixmap(Nextimage);
grid->addWidget(imageLabel,0,0);
grid->addWidget(imageLabel,0,1);

what is the reason behind this?Information on this would be helpful.

wysota
20th February 2009, 11:26
You can't add the same widget two times to the layout. If you do that the widget will be removed from the first layout and put into the second one.

prajna
20th February 2009, 11:55
I tried using different widget.Again the same problem.
What can be the problem...


QGridLayout *grid = new QGridLayout();

//grid->setColumnMinimumWidth(2,30);
imageLabel = new QLabel;
imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
imageLabel->setScaledContents(true);
setCentralWidget(imageLabel);
resize(50,50);
QString NextImagepath = "c:\\Data\\Images\\Pictures\\error.bmp";
QPixmap Nextimage(NextImagepath);
imageLabel->setPixmap(Nextimage);
grid->addWidget(imageLabel,0,0);



ilabel2 = new QLabel;
ilabel2->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
ilabel2->setScaledContents(true);
setCentralWidget(imageLabel);
resize(50, 50);
QString NextImagepath1 = "c:\\Data\\Images\\Pictures\\b_prevtrack_on.png";
QPixmap Nextimage1(NextImagepath1);
ilabel2->setPixmap(Nextimage1);
grid->addWidget(ilabel2,2,1);

wysota
20th February 2009, 19:39
This time you are replacing one central widget with another so again you only see one widget and the other gets deleted (or hidden). Please stop guessing and look into the documentation of QGridLayout, there is an example there that shows how to add widgets to the layout.