Next we add the image zoom function for this project:
Add a slot function:
void Showzoomin (); About the zoom function of a picture
Add the appropriate response connection
Connect (zoominaction, SIGNAL (triggered ()), this, SLOT (Showzoomin ())); To zoom in on a picture
The implementation of the slot function:
To achieve a picture enlargement void imageprocessor::showzoomin () { //first determine if there is a photo if (img.isnull ()) return; No photos, then do not enlarge the Qmatrix Martix; A picture of the storage object Martix.scale (2, 2); Both length and width are magnified twice times img = img.transformed (Martix); The operation of the picture is implemented showwidget->imagelabel->setpixmap (Qpixmap::fromimage (IMG)); Change the picture to put it back}
Similarly, add the Zoom Out feature:
The corresponding slot functions and connections are also added in front:
void Showzoomout (); Picture shrinking
Connect (zoomoutaction, SIGNAL (triggered ()), this, SLOT (Showzoomout ())); Take a picture and put it small
void Imageprocessor::showzoomout () { //first determine if there is a photo if (img.isnull ()) return; No photos, then do not enlarge the Qmatrix Martix; A picture of the storage object Martix.scale (0.5, 0.5); Both length and width are magnified twice times img = img.transformed (Martix); The operation of the picture is implemented showwidget->imagelabel->setpixmap (Qpixmap::fromimage (IMG)); Change the picture to put it back}
Other specific code bases look ahead: http://blog.csdn.net/cutter_point/article/details/42839071
Operation Result: Original:
Button zoom: Zoom Out:
"QT5 Development and examples" 13. Implement a simple text editor 2