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

Zooming in and out

OK. We have successfully displayed the image. Now, let's scale it. Here, we take zooming in as an example. With the experience from the preceding actions, we should have a clear idea as to how to do that. First, we declare a private slot, which is named zoomIn, and give its implementation as shown in the following code:

     void MainWindow::zoomIn()
{
imageView->scale(1.2, 1.2);
}

Easy, right? Just call the scale method of imageView with a scale rate for the width and a scale rate for the height. Then, we connect the triggered signal of zoomInAction to this slot in the createActions method of the MainWindow class:

     connect(zoomInAction, SIGNAL(triggered(bool)), this, SLOT(zoomIn()));

Compile and run the application, open an image with it, and click on the Zoom in button on the toolbar. You will find that the image enlarges to 120% of its current size on each click.

Zooming out just entails scaling the imageView with a rate of less than 1.0. Please try to implement it by yourself. If you find it difficult, you can refer to our code repository on GitHub (https://github.com/PacktPublishing/Qt-5-and-OpenCV-4-Computer-Vision-Projects/tree/master/Chapter-01).

With our application, we can now open an image and scale it for viewing. Next, we will implement the function of the saveAsAction action.

主站蜘蛛池模板: 内江市| 北流市| 金昌市| 阿图什市| 绥德县| 兴海县| 龙川县| 波密县| 冕宁县| 柳江县| 厦门市| 方山县| 富源县| 利津县| 泸水县| 阿巴嘎旗| 蓬溪县| 高台县| 扎兰屯市| 白银市| 昆山市| 得荣县| 安达市| 遂川县| 文昌市| 商南县| 河北区| 深水埗区| 疏勒县| 喀什市| 姚安县| 岑溪市| 衡阳县| 分宜县| 西乌珠穆沁旗| 义乌市| 赤峰市| 祁门县| 高阳县| 吴忠市| 潢川县|