Qt5 Tutorial QActions and Icon Resources - 2020
In this tutorial, we will learn more about MainWindow's Toolbar and Menubar as well as resources for icons. We'll link those icons with the menu items. The icons used in this example are here.
So, this section is the continuation from MainWindow and Action and Resource Files (.qrc).
Whenever we add an item to the menu, Qt automatically sync with Action Editor. As we can see from the picture below, all the added items appear in the Action Editor:
We can open a dialog to edit Actions either by right mouse click or double click on the Action in Action Editor:
We'll be back to this Action items later in this section.
Now, we need to make resources:
Right click on the Project->Add New...->Qt->Qt Resource File.
Type in the name (MyRes)->Next->Finish.
Double click MyRes.qrc->Add->Add Prefix
We'll use "/images" as a prefix.
Add->Add Files:
After adding all the icons, they will show up in the list of resources:
Save all resources by right click on MyRes.qrc* in the Open Documents pane which is at the lower left corner of the Designer.
Open the "Edit action" dialog by right click on the actionNew item in the Action Editor.
Then put the proper icon for the "New" menu:
After repeating the selection for all icons, each actions will have its own icon:
Now, let's drag each action items and drop onto the tool bar area:
Let's check everything is fine. If we run the application:
OK, looks great!
Those menus we created looks great, however, they do nothing when we click them.
So, let put handle the signals triggered by the menu items.
Right click on action in the Action Editor:
Then, we need to add some lines of code into the mainwindow.cpp:
void MainWindow::on_actionSave_triggered() { QMessageBox msgBox; msgBox.setText("save action"); msgBox.exec(); }
So, when we click "Save", we get the following message:
Qt 5 Tutorial
- Hello World
- Signals and Slots
- Q_OBJECT Macro
- MainWindow and Action
- MainWindow and ImageViewer using Designer A
- MainWindow and ImageViewer using Designer B
- Layouts
- Layouts without Designer
- Grid Layouts
- Splitter
- QDir
- QFile (Basic)
- Resource Files (.qrc)
- QComboBox
- QListWidget
- QTreeWidget
- QAction and Icon Resources
- QStatusBar
- QMessageBox
- QTimer
- QList
- QListIterator
- QMutableListIterator
- QLinkedList
- QMap
- QHash
- QStringList
- QTextStream
- QMimeType and QMimeDatabase
- QFile (Serialization I)
- QFile (Serialization II - Class)
- Tool Tips in HTML Style and with Resource Images
- QPainter
- QBrush and QRect
- QPainterPath and QPolygon
- QPen and Cap Style
- QBrush and QGradient
- QPainter and Transformations
- QGraphicsView and QGraphicsScene
- Customizing Items by inheriting QGraphicsItem
- QGraphicsView Animation
- FFmpeg Converter using QProcess
- QProgress Dialog - Modal and Modeless
- QVariant and QMetaType
- QtXML - Writing to a file
- QtXML - QtXML DOM Reading
- QThreads - Introduction
- QThreads - Creating Threads
- Creating QThreads using QtConcurrent
- QThreads - Priority
- QThreads - QMutex
- QThreads - GuiThread
- QtConcurrent QProgressDialog with QFutureWatcher
- QSemaphores - Producer and Consumer
- QThreads - wait()
- MVC - ModelView with QListView and QStringListModel
- MVC - ModelView with QTreeView and QDirModel
- MVC - ModelView with QTreeView and QFileSystemModel
- MVC - ModelView with QTableView and QItemDelegate
- QHttp - Downloading Files
- QNetworkAccessManager and QNetworkRequest - Downloading Files
- Qt's Network Download Example - Reconstructed
- QNetworkAccessManager - Downloading Files with UI and QProgressDialog
- QUdpSocket
- QTcpSocket
- QTcpSocket with Signals and Slots
- QTcpServer - Client and Server
- QTcpServer - Loopback Dialog
- QTcpServer - Client and Server using MultiThreading
- QTcpServer - Client and Server using QThreadPool
- Asynchronous QTcpServer - Client and Server using QThreadPool
- Qt Quick2 QML Animation - A
- Qt Quick2 QML Animation - B
- Short note on Ubuntu Install
- OpenGL with QT5
- Qt5 Webkit : Web Browser with QtCreator using QWebView Part A
- Qt5 Webkit : Web Browser with QtCreator using QWebView Part B
- Video Player with HTML5 QWebView and FFmpeg Converter
- Qt5 Add-in and Visual Studio 2012
- Qt5.3 Installation on Ubuntu 14.04
- Qt5.5 Installation on Ubuntu 14.04
- Short note on deploying to Windows
Ph.D. / Golden Gate Ave, San Francisco / Seoul National Univ / Carnegie Mellon / UC Berkeley / DevOps / Deep Learning / Visualization