I put together a quick demo application to verify this bug, it loads an image. Could anyone run this program, load an image file and zoom out (zooming in seems to work quite well.)
main.cpp:
#include <QtGui>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
MainWindow w;
w.show();
return a.exec();
}
#include <QtGui>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui>
{
Q_OBJECT
public:
~MainWindow();
private slots:
void zoomIn();
void zoomOut();
private:
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void zoomIn();
void zoomOut();
private:
QAction *Action_zoomIn;
QAction *Action_zoomOut;
QMenu *Menu_view;
QGraphicsScene * scene;
QGraphicsView * view;
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
And mainwindow.cpp:
#include "mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
){
Action_zoomIn
= new QAction(tr
("Zoom In"),
this);
Action_zoomIn->setShortcut(tr("="));
Action_zoomOut
= new QAction(tr
("Zoom Out"),
this);
Action_zoomOut->setShortcut(tr("-"));
Menu_view
= new QMenu(tr
("View"),
this);
Menu_view->addAction(Action_zoomIn);
Menu_view->addAction(Action_zoomOut);
menuBar()->addMenu(Menu_view);
scene->addText("No files loaded...");
this->setCentralWidget(view);
this->show();
, tr("Open File")
, ""
, tr("All Files (*)")
, &selectFilt
, options);
scene->clear();
//This seems to work much better: (no crashes at least)
//pixitem->setTransformationMode(Qt::SmoothTransformation);
connect(Action_zoomIn, SIGNAL(triggered()), this, SLOT(zoomIn()));
connect(Action_zoomOut, SIGNAL(triggered()), this, SLOT(zoomOut()));
}
MainWindow::~MainWindow()
{
}
void MainWindow::zoomIn()
{
view->scale(2.0,2.0);
}
void MainWindow::zoomOut()
{
view->scale(0.5,0.5);
}
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
Action_zoomIn = new QAction(tr("Zoom In"), this);
Action_zoomIn->setShortcut(tr("="));
Action_zoomOut = new QAction(tr("Zoom Out"), this);
Action_zoomOut->setShortcut(tr("-"));
Menu_view = new QMenu(tr("View"), this);
Menu_view->addAction(Action_zoomIn);
Menu_view->addAction(Action_zoomOut);
menuBar()->addMenu(Menu_view);
scene = new QGraphicsScene();
scene->addText("No files loaded...");
view = new QGraphicsView(scene, this);
this->setCentralWidget(view);
this->show();
QFileDialog::Options options;
QString selectFilt;
QString imgname = QFileDialog::getOpenFileName(this
, tr("Open File")
, ""
, tr("All Files (*)")
, &selectFilt
, options);
scene->clear();
QGraphicsPixmapItem * pixitem = scene->addPixmap( QPixmap(imgname) );
//This seems to work much better: (no crashes at least)
//pixitem->setTransformationMode(Qt::SmoothTransformation);
connect(Action_zoomIn, SIGNAL(triggered()), this, SLOT(zoomIn()));
connect(Action_zoomOut, SIGNAL(triggered()), this, SLOT(zoomOut()));
}
MainWindow::~MainWindow()
{
}
void MainWindow::zoomIn()
{
view->scale(2.0,2.0);
}
void MainWindow::zoomOut()
{
view->scale(0.5,0.5);
}
To copy to clipboard, switch view to plain text mode
(I also tried with qpixmap allocated differently. I use fromImage() in some other code, where the image is never "deleted" to make sure the data exists.
Is the above code correct? Does qt keep an internal reference count on pixmaps...?)
Bookmarks