问题标签 [qgraphicspixmapitem]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c++ - QT:即使在 static_cast 之后也无法在主窗口中设置对象的位置
我正在制作一个小游戏,我希望游戏中的敌人同时移动并自动生成子弹。
到目前为止,我的敌人可以自动移动并产生子弹,但问题是
我的子弹无法跟随敌人的移动并在敌人的不同起点产生。
更加具体,
每次敌人产生子弹时,我都想抓住敌人的位置。但是,我不能动态设置我的子弹。
现在,我分别设计了移动敌人的函数(enemyMove())和生成子弹的函数(MakeBall())。我在我的主窗口构造函数中为每个函数设置了一个不同的计时器,以便在每个时间窗口自动调用该函数。
到目前为止我的尝试和想法:
- 我的敌人是 Enemy 类的对象,但我在主窗口构造函数中将此对象静态转换为 QGraphicsPixmapItem,所以我认为它应该能够将敌人用作 QGraphicsPixmapItem。但是,当我尝试在 MakeBall() 函数中执行诸如enemy- >x()之类的操作时,编译器强制结束。
- 我将敌人的位置作为参数发送给 MakeBall 函数,以便子弹可以在敌人的位置设置位置。但是,编译器说这是从“int”类型的右值对“int&”类型的非常量引用进行的无效初始化。
- 我将 QGraphicsPixmapItem *enemy 作为参数发送给 MakeBall 函数并使用enemy->x() 来捕捉它的位置,但是它最终甚至没有产生任何子弹,这意味着 MakeBall 函数从未成功调用。
任何分享或建议都将不胜感激。非常非常感谢你。
主窗口.cpp
主窗口.h
敌人子弹.cpp
敌人子弹.h
敌人.cpp(修剪到本质。它实际上可以在直线上从左到右和从右到左反复移动。所以我们无法计算产生子弹的具体时间,因为每个位置都会一次又一次地重新访问。)
敌人.h
qt - Qt:将 QGraphicsPixmapItems 列表添加到场景组?
我正在尝试将 QGraphicsPixmapItems 列表分组到 QGraphicsScene 中。但是,我看到我只能将 QGraphicsItems 列表添加到场景中。将 QGraphicsPixmapItems 列表类型转换为 QGraphicsItems 列表的最佳方法是什么?对于 qt 项目,是否有特定的方法来执行此操作?或者,是否有更好的方法将 QGraphicsPixmapItems 列表添加到场景组?
只是为了说明问题,在下面的代码中,我创建了 5 个尝试添加的空白像素图。
任何帮助,将不胜感激。谢谢!
python - How do I reimplement the itemChange and mouseMoveEvent of a QGraphicsPixmapItem?
I'm building a T Shirt Designer using PySide. For this, I've set up a QGraphicsScene with the image of the T Shirt as a QPixmapItem on the scene. To overlay the design on the T Shirt, I'm getting the design image PNG from the user and setting that up as another QPixmapItem. I align them up using the setPos() method and then use the setZValue() method to ensure that the Design PNG shows up on top of the T Shirt image.
I've enabled the flags ItemIsMovable, ItemIsSelectable, ItemSendsScenePositionChanges, ItemIsFocusable for the Design image QPixmapItem. So I am able to move the design around over the T Shirt image. Next, I want to restrict this movement to only where the printing is possible. To achieve this, I've followed this question to derive a new QGraphicsPixmapItem class and have tried to reimplement both the itemChange() and the mouseMoveEvent() methods.
Inside these methods, I've tried calling the same methods of the original QPixmapItem class using both super() as well as the regular way QGraphicsPixmapItem.itemChange(change, event). However, nothing seems to be happening. The design moves just fine but it's not getting restricted. To see if the method gets called I added print statements inside these methods but they don't get executed.
I've tried adding setSceneRect() in the scene as well. I've also enabled setMouseTracking on the QGraphicsView. However, none of those things triggers either the itemChanged() or mouseMoveEvent().
There are other questions where people have explained how to do this in C++. However, I'm not able to replicate it in python.
python - 将端口添加到 QGraphicsPixmapItem 对象
我创造了这样的东西。我创建了一个可以添加到 QGraphicsView 的 QGraphicsPixmapItem 对象。我想为我创建的这些对象添加端口。我想在这些端口和我创建的对象之间建立联系。我不知道该怎么做。你能帮助我吗 ?
我的代码
python - 在pyqt5中使用QPainterPath填充绘制的路径
我有一个加载图像的 QGraphicsView。然后我做了它,这样你就可以用 QPainterPath 的指针在图像上绘制,然后通过连接起点和终点来关闭路径。我想知道如何在释放鼠标后填充该区域,然后使该对象可选择但不可移动。
我尝试使用 QPaint 并填充 addGraphicsItem 函数中看到的路径。
我希望 addGraphicsItem 函数然后填充对象,但没有任何变化。
python - Painting QGraphicsPixmapItem border on hover
I'm trying to create my own QGraphicsPixmapItem where I can active on hover mode and I want to paint a black border when I hover over the rect of the item, and go back to normal when I leave the rect space.
I started this code, but don't know what to do next. Also wanted to do a paintEvent, but QGraphicsPixmapItems doesn't have that. So am even more confused as don't think the paint method would be the same.
#xA;I could make the hover print 'hello' but can't do anything else, even with some examples, because those are with paintEvent and other type of items.
I would like to maintain the type of item if possible and paint the border as i said. But also don't know if it would be a better approach that's also simple.
qt - QGraphicsPixmapItem 不显示在 QGraphicsScene
在继承自 QGraphicsItem 的类 GraphicWidgetItem 中,我创建了矩形、圆形和图片。除了图片,一切都显示出来了。我究竟做错了什么?