Quote Originally Posted by munna
can i see the code where you are doing this?
Here is the file:

Its the open() function which does the functioning.

Qt Code:
  1. #include "imagezoomer.h"
  2. #include <QtGui>
  3. #include <qdir.h>
  4. #include <QColor>
  5.  
  6. ImageZoomer::ImageZoomer(Ui::MainWindow *_mwin): mwin(_mwin)
  7. {
  8.  
  9. frame = new QFrame(mwin->centralwidget);
  10. frame->setGeometry(QRect(60, 70, 591, 571));
  11. frame->setFrameShape(QFrame::StyledPanel);
  12. frame->setFrameShadow(QFrame::Plain);
  13.  
  14. canvas = new Q3Canvas(500,500);
  15. canview = new Q3CanvasView(frame);
  16. canview->setCanvas(canvas);
  17. canvas->setBackgroundColor(Qt::black);
  18.  
  19. resize(500, 400);
  20. connect(mwin->actionOpen, SIGNAL(activated()), this, SLOT(open()));
  21.  
  22. }
  23. ImageZoomer::~ImageZoomer()
  24. {
  25. }
  26.  
  27. void ImageZoomer::open()
  28. {
  29. int x,y;
  30. QString filename = QFileDialog::getOpenFileName(this, tr("Open File"),QDir::currentPath());
  31.  
  32. if (!filename.isEmpty())
  33. {
  34. QImage image(filename);
  35. if (image.isNull())
  36. {
  37. QMessageBox::information(this, tr("Image Zoomer"),tr("Cannot load %1.").arg(filename));
  38. return;
  39. }
  40. canvas->setBackgroundPixmap(QPixmap::fromImage(image));
  41. scalefactor = 1.0;
  42.  
  43. x = image.width();
  44. y = image.height();
  45.  
  46. canview->resizeContents(x,y);
  47.  
  48. }
  49. }
To copy to clipboard, switch view to plain text mode