简体   繁体   中英

Resize QGraphicsPixmapItem

I need to place a clickable picture on the QGraphicsScene. This is how I did it:

class myGraphicsPixmapItem: public QGraphicsPixmapItem 
{
public:
    myGraphicsPixmapItem() { }

    ~myGraphicsPixmapItem() {}

    void mousePressEvent(QGraphicsSceneMouseEvent* event)
    {
        qDebug() << "Clicked!";

    }
};


QPixmap pic;
pic.load(":/img/pic.png");

QGraphicsScene* scene = new QGraphicsScene();
view = new GraphicsView(scene);

myGraphicsPixmapItem* pixmapItem = new myGraphicsPixmapItem;
pixmapItem->setPixmap(pic);
scene->addItem(pixmapItem);

But I don't know how to make it smaller. Please tell, how to make smaller QGraphicsPixmapItem or is there another way to place a clickable and resizable picture on the QGraphicsScene?

you should use scaled QPixmap::scaled instead of QGraphicsPixmapItem . sample code :

QPixmap bgPixmap(fileName);
QPixmap scaled = bgPixmap.scaled(QSize(64, 64));

and use scaled as your QPixmap .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM