Qgraphicsview How to add and change picture Size! __qgraphicview

Source: Internet
Author: User

1 Create engineering Scale, base class for Qwidget, use layout layout, engineering files for main.cpp widget.h widget.cpp

A Add 2 button controls ZoomIn and Zoomout.

b Add Control Qgraphicsview.

C Signal for clicked

2 widget.h.

#include <QtCore>
#include <QtGui>
#include <QGraphicsItem>
#include <QGraphicsView>
#include <QWidget>
Private
    Qreal num;
    
    QString filename;
    Qpixmap Pixmap;
    Qgraphicsitem *item;
    Qgraphicsscene *scene;

Class in the constructor of the 3 widget.cpp.

    
    num=0;  Size scale
    Scene = new Qgraphicsscene (this);
    Ui->graphicsview->setscene (Scene);
    
    
    Pixmap.load (filename);
    Filename= "1.jpg";
    Item=scene->addpixmap (PIXMAP);
    Item->setflag (qgraphicsitem::itemismovable);
    Item->setscale (0.1); Default Load Scale
In the CAO function of the 4 widget.cpp
void Widget::on_zoomin_clicked ()
{
    num=num+0.1;
    Item->setscale (num);
    Qdebug ("num +:%d", num);
}
void Widget::on_zoomout_clicked ()
{
    num=num-0.1;
    Item->setscale (num-0.1);
    Qdebug ("Num 1:%d", num);
}
Click on the button will be the picture larger or smaller, pay attention to num value, not less than 0;
		To be Continued ...
                                                           

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.