- Qt 5 and OpenCV 4 Computer Vision Projects
- Zhuo Qingliang
- 317字
- 2021-06-24 13:59:19
Adding the blur action
Most of the actions we will add in this chapter will be used to edit an image, so we should categorize them in a new menu and toolbar. First, we will declare three members, that is, the edit menu, the edit toolbar, and the blur action, in the private section of the mainwindow.h header file:
QMenu *editMenu;
QToolBar *editToolBar;
QAction *blurAction;
Then, we will create them in the MainWindow::initUI and MainWindow::createActions methods, respectively, as follows:
In MainWindow::initUI, this is executed as follows:
editMenu = menuBar()->addMenu("&Edit");
editToolBar = addToolBar("Edit");
In MainWindow::createActions, this is executed as follows:
blurAction = new QAction("Blur", this);
editMenu->addAction(blurAction);
editToolBar->addAction(blurAction);
Up until now, we have an edit menu and an edit toolbar with a blur action on both of them. But, if the user clicks either the blur buttons on the toolbar or the blur items under the edit menu, nothing will happen. This is because we haven't connected a slot to that action yet. Let's give the action a slot now. First, we will declare a slot in the private slots section of mainwindow.h, as follows:
// for editting
void blurImage();
Then, we will give it a dummy implementation in mainwindow.cpp:
void MainWindow::blurImage()
{
qDebug() << "Blurring the image!";
}
Now that the slot is ready, it's time to connect the triggered signal of the blur action with this slot at the end of the mainwindow::createActions method:
connect(blurAction, SIGNAL(triggered(bool)), this, SLOT(blurImage()));
When you compile and run the application, you will see the menu, toolbar, and the action. If you trigger the action by clicking it, you will see the message Blurring the image! being printed.
This is what the window and printed message look like:

The UI part is now ready, which means that we can focus on how to blur the image by using OpenCV in the slot in the following sections.
- 黑客攻防從入門到精通(實戰(zhàn)秘笈版)
- C++面向對象程序設計(第三版)
- Power Up Your PowToon Studio Project
- Windows系統(tǒng)管理與服務配置
- Software Testing using Visual Studio 2012
- JavaScript by Example
- 微信公眾平臺開發(fā):從零基礎到ThinkPHP5高性能框架實踐
- 深度學習:算法入門與Keras編程實踐
- R Data Analysis Cookbook(Second Edition)
- The Professional ScrumMaster’s Handbook
- Rust游戲開發(fā)實戰(zhàn)
- Node.js 12實戰(zhàn)
- AMP:Building Accelerated Mobile Pages
- 大規(guī)模語言模型開發(fā)基礎與實踐
- C語言程序設計教程