irmakci
18th July 2008, 12:59
:confused:
Hi,
I used the code below normally in QApplication
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QPixmap pix;
QGraphicsView* gr;
//QImage image;
QString currentFile = QFileDialog::getOpenFileName(0,"Open File", QDir::currentPath());
QImage image(currentFile);
QGraphicsScene scene = new QGraphicsScene();
//pix.load(":/Resources/open.png");
//pix.load(currentFile);
scene.addPixmap(QPixmap::fromImage(image));
gr= new QGraphicsView();
gr->setScene(&scene);
//setCentralWidget(gr);
gr->show();
return a.exec();
}
and this works. I can see the image loaded.
But when I used the same code in QMainWindow
such as
deneme::deneme(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);
QPixmap pix;
QGraphicsView* gr;
//QImage image;
QString currentFile = QFileDialog::getOpenFileName(0,"Open File", QDir::currentPath());
QImage image(currentFile);
QGraphicsScene scene = new QGraphicsScene();
scene.addPixmap(QPixmap::fromImage(image));
gr= new QGraphicsView();
//gr->setBackgroundBrush(QImage(currentFile));
//gr->setForegroundBrush(QImage(currentFile));
gr->setScene(&scene);
//setCentralWidget(gr);
gr->show();
}
this does not work. And I can only see white graphics widget when I loaded the image.
How can I solve this problem. Thanks in advance
regards
Hi,
I used the code below normally in QApplication
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QPixmap pix;
QGraphicsView* gr;
//QImage image;
QString currentFile = QFileDialog::getOpenFileName(0,"Open File", QDir::currentPath());
QImage image(currentFile);
QGraphicsScene scene = new QGraphicsScene();
//pix.load(":/Resources/open.png");
//pix.load(currentFile);
scene.addPixmap(QPixmap::fromImage(image));
gr= new QGraphicsView();
gr->setScene(&scene);
//setCentralWidget(gr);
gr->show();
return a.exec();
}
and this works. I can see the image loaded.
But when I used the same code in QMainWindow
such as
deneme::deneme(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);
QPixmap pix;
QGraphicsView* gr;
//QImage image;
QString currentFile = QFileDialog::getOpenFileName(0,"Open File", QDir::currentPath());
QImage image(currentFile);
QGraphicsScene scene = new QGraphicsScene();
scene.addPixmap(QPixmap::fromImage(image));
gr= new QGraphicsView();
//gr->setBackgroundBrush(QImage(currentFile));
//gr->setForegroundBrush(QImage(currentFile));
gr->setScene(&scene);
//setCentralWidget(gr);
gr->show();
}
this does not work. And I can only see white graphics widget when I loaded the image.
How can I solve this problem. Thanks in advance
regards