Reputation: 3
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?
Upvotes: 0
Views: 4686
Reputation: 378
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 .
Upvotes: 1