Halordain
10th February 2011, 09:36
Hi,
I extended QGraphicsView and, in its constructor, want to load a few pixmaps to display on-screen. To test that the pixmaps are properly loaded, I use qWarning (see below), and from what I can tell in the watch window locals, the image is being loaded. However, past that point, I don't know how to check the data in QLabel if it isn't showing up properly on screen. QLabels are loaded into QGraphicsGridLayout, which is then setLayout into the top-level QGraphicsObject:
MyViewer::MyViewer(QGraphicsScene *scene)
{
QGraphicsGridLayout *layout = new QGraphicsGridLayout;
img_board.resize(8);
for (int i = 0; i < 8; ++i)
img_board[i].resize(8);
for (int j = 0; j < 8; ++j) {
for (int i = 0; i < 8; ++i) {
int index = 8*i + j;
char buffer[200];
QString qindex = itoa(index, buffer, 10);
QString filename(qApp->applicationDirPath() + "/img/");
filename += qindex;
filename += ".png";
QPixmap qimg;
if (qimg.load(filename))
qWarning("Failed to load target image");
img_board[j][i] = new QLabel;
img_board[j][i]->setPixmap(qimg);
QGraphicsProxyWidget* pixwidget = scene->addWidget(img_board[j][i]);
layout->addItem(pixwidget, i, j + 1);
}
}
QGraphicsWidget* form = new QGraphicsWidget;
form->setLayout(layout);
scene->addItem(form);
setWindowTitle(tr("TESTING"));
resize(800, 600);
form->show();
}
.....
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QGraphicsScene* scene = new QGraphicsScene;
MyViewer window(scene);
window.show();
return app.exec();
}
The application builds and runs, but the window is just one large white box. I tried digging into img_board as well as layout in the debugger, but the values are a bunch of addresses, with nothing I can use to verify that I properly loaded the pixmap. However, the warnings have stopped, so loads are working, I think.
Thanks for your help!
I extended QGraphicsView and, in its constructor, want to load a few pixmaps to display on-screen. To test that the pixmaps are properly loaded, I use qWarning (see below), and from what I can tell in the watch window locals, the image is being loaded. However, past that point, I don't know how to check the data in QLabel if it isn't showing up properly on screen. QLabels are loaded into QGraphicsGridLayout, which is then setLayout into the top-level QGraphicsObject:
MyViewer::MyViewer(QGraphicsScene *scene)
{
QGraphicsGridLayout *layout = new QGraphicsGridLayout;
img_board.resize(8);
for (int i = 0; i < 8; ++i)
img_board[i].resize(8);
for (int j = 0; j < 8; ++j) {
for (int i = 0; i < 8; ++i) {
int index = 8*i + j;
char buffer[200];
QString qindex = itoa(index, buffer, 10);
QString filename(qApp->applicationDirPath() + "/img/");
filename += qindex;
filename += ".png";
QPixmap qimg;
if (qimg.load(filename))
qWarning("Failed to load target image");
img_board[j][i] = new QLabel;
img_board[j][i]->setPixmap(qimg);
QGraphicsProxyWidget* pixwidget = scene->addWidget(img_board[j][i]);
layout->addItem(pixwidget, i, j + 1);
}
}
QGraphicsWidget* form = new QGraphicsWidget;
form->setLayout(layout);
scene->addItem(form);
setWindowTitle(tr("TESTING"));
resize(800, 600);
form->show();
}
.....
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QGraphicsScene* scene = new QGraphicsScene;
MyViewer window(scene);
window.show();
return app.exec();
}
The application builds and runs, but the window is just one large white box. I tried digging into img_board as well as layout in the debugger, but the values are a bunch of addresses, with nothing I can use to verify that I properly loaded the pixmap. However, the warnings have stopped, so loads are working, I think.
Thanks for your help!