In createActionsAndConnections() we initialize the standard openAction and 4 QActions associated with the recentFileActionList. In the MainWindow constructor we initialize the value of maxFileNr and create the actions, menus and connections. Void adjustForCurrentFile(const QString& filePath) Please also notice the QLabel *imageLabel that will hold the image that we load from a file. You can read about the details of these functions below.
They are not stored as member variables of the MainWindow! This enables other instances of the program to access recently opened files, as well.īelow you can see the declaration of the MainWindow with the above-mentioned requirements. The names and paths of the recently opened files are stored in the configuration file that can be accessed via QSettings.
We create a constant number of QActions at the beginning and then update their text, data, and visibility whenever the user opens another file. We do not create actions every time there is a change in the recently opened files. Hello, Im trying to show a QImage into qgraphicsView, but it never works, I tried the following code: QGraphicsScene scene new QGraphicsScene QImage image ( 'path/QtImage.jpg' ) QGraphicsPixmapItem item (QPixmap::fromImage (image)) scene->addItem (&item) ui->graphicsView->setScene (scene) I fist create a scene,then trnasform the image. The number of actions in the menu remains constant (i.e. The recently opened files are represented by a list of QActions.There are two important points to stress about the current implementation: function loadFile(QString) and two helper functions adjustForCurrentFile(QString) and updateRecentActionList(QString).QString currentFilePath that stores the path of the recently opened file.const int maxFileNr representing the maximum number of files that can be held in the recentFilesMenu.This list of actions represents the recently opened files a list of QActions QList recentFileActionList.a slot openRecent() that is called anytime we choose a file from recentFilesMenu.You might want to take a look at Qts Image Viewer Example. a submenu QMenu* recentFilesMenu which will appear after we click on Open Recent Hey Friends I am using QLabel For Display The Image Now I Want Zoom In And Zoom Out Functionality In Image + Button For Zoom In - Button For Zoom Out Plz Help Me To Slove This Problem My Ui Like This Thanks In Advance.To implement Open Recent we need to introduce the following objects and functions: For an image viewer please look at this official Qt example.
This code was written to explain Open Recent functionality rather than an image viewer. Note: Please do not use this implementation if you want a proper image viewer.