在Qt5中更改QGraphicsScene/View中的Pixmap位置
Change Pixmap Position in QGraphicsScene/View in Qt5
我有一个普通的QGraphicsView/QGraphicsScene,我想做的就是将QPixmap(.png)加载到图形中,并手动设置该QPixmap图像的位置。我找到了解决方案,但它们在Qt5上不起作用。关于如何在Qt5上实现这一点,有什么想法吗?非常感谢。
QGraphicsScene* scene = new QGraphicsScene(QRect(0, 0, 600, 400));
QPixmap Pix(":/test.gif");
// doesnt work
//Pix.setGeometry(QRect(-30, 40, 260, 200));
QGraphicsPixmapItem *item1 = scene->addPixmap(Pix);
// doesnt work
//item1->setPos(-25, 45);
//scene->addPixmap(Pix)->setPos(0,0);
//QGraphicsView* view = new QGraphicsView(ui->centralWidget);
QGraphicsView* view = new QGraphicsView(this);
view->setScene(scene);
您可以从计算机中浏览图像并设置其位置。以防万一,它能帮助别人。
QString fileNamez = QFileDialog::getOpenFileName(this,"Open Filezzz","C:/");
QGraphicsPixmapItem *pm = scene->addPixmap( QPixmap(fileNamez) );
pm->setPos(xPos,yPos);
如果在实现中使用QGraphicsPixmapItem,或者实际上使用任何Qt对象,则需要将其包含在cpp:-中
#include <QGraphicsPixmapItem>
相关文章:
- 将成员变量添加到共享库中的类中,不会破坏二进制兼容性吗
- .cpp和.h文件中的模板专用化声明
- 反向给定链表中的K节点
- 正在查找文档以获得PS4平台的C++中的设备信息
- enum是C++中的宏变量还是整数变量
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- 将字符串存储在c++中的稳定内存中
- 文本文件中的单词链表
- 递归函数计算序列中的平方和(并输出过程)
- 如何从C++中的依赖类型中获得它所依赖的类型
- C++中的"inline"关键字
- 如何运行位于boost/libs/python/example/tutorial目录中的hello.cpp和Jamfil
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 用C++中的一个变量定义一个常量
- vector.resize()中的分配错误
- 使用指针从C++中的数组中获取最大值
- 范围中的"range"和"view"有什么区别sv3 ts?
- C++中的numpy“.view”函数
- 为什么我不能在SQLite中的VIEW上创建触发器
- 在Qt5中更改QGraphicsScene/View中的Pixmap位置