
Hi,
I used the code below normally in QApplication
int main(int argc, char *argv[])
{
//QImage image;
//pix.load(":/Resources/open.png");
//pix.load(currentFile);
scene.
addPixmap(QPixmap::fromImage(image
));
gr->setScene(&scene);
//setCentralWidget(gr);
gr->show();
return a.exec();
}
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();
}
To copy to clipboard, switch view to plain text mode
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
){
ui.setupUi(this);
//QImage image;
scene.
addPixmap(QPixmap::fromImage(image
));
//gr->setBackgroundBrush(QImage(currentFile));
//gr->setForegroundBrush(QImage(currentFile));
gr->setScene(&scene);
//setCentralWidget(gr);
gr->show();
}
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();
}
To copy to clipboard, switch view to plain text mode
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
Bookmarks