官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 景东| 临漳县| 噶尔县| 大竹县| 玉环县| 廉江市| 都安| 上虞市| 黔江区| 菏泽市| 惠水县| 皋兰县| 霍林郭勒市| 沂南县| 宁乡县| 弥渡县| 北辰区| 寻甸| 乌苏市| 武功县| 阿拉尔市| 普兰县| 台江县| 花莲市| 晴隆县| 信阳市| 柳河县| 浑源县| 谢通门县| 昌邑市| 霍山县| 山丹县| 竹溪县| 军事| 公安县| 清涧县| 龙岩市| 博乐市| 洛南县| 平山县| 龙川县|