"QT5 Development and examples" 13. Implement a simple text editor 2

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.