我需要在QGraphicsScene上放置一个可点击的图片。我是这样做的:
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);但我不知道怎么把它变小。请告诉我,如何使QGraphicsPixmapItem更小,或者是否有其他方法可以在QGraphicsScene上放置可点击和可调整大小的图片?
发布于 2018-04-06 14:33:17
您应该使用缩放的QPixmap::scaled而不是QGraphicsPixmapItem。示例代码:
QPixmap bgPixmap(fileName);
QPixmap scaled = bgPixmap.scaled(QSize(64, 64));并使用scaled作为QPixmap。
https://stackoverflow.com/questions/46832691
复制相似问题