Let's get started by using the following steps:
- First, open up mainwindow.h and add the following headers:
#include <QMainWindow> #include <QFileDialog> #include <QPixmap> #include <QPainter>
- Then, add the following variable, called imageBuffer, which will serve as the pointer that points to the actual image data before rescaling. Then, add the functions as well:
private: Ui::MainWindow *ui; QPixmap* imageBuffer; public: void resizeImage(); void paintEvent(QPaintEvent *event);public slots: void on_actionOpen_triggered();
- Next, open up mainwindow.cpp and initialize the imageBuffer variable in the class constructor:
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) ...