[英]Qt Graphics, Move an object forward or backward
I have two object: CQWater and CQTank. 我有两个对象:CQWater和CQTank。 My CQTank will disappear if he has the same position.
如果他的职位相同,我的CQTank将消失。 What should I do to move a tank forward.
我应该怎么做才能使坦克前进。
CQWater::CQWater( QGraphicsScene *scena )
{
// drew the rect
setPixmap(QPixmap(":/new/prefix1/images/woda.png"));
setTransformOriginPoint(50,50);
setRotation(180);
woda = new CWater();
setPos(woda->x, woda->y);
scena->addItem(this);
}
TANK: 罐:
CQTank::CQTank( QGraphicsScene *scena )
{
czolg = new CTank();
setPos(czolg->x, czolg->y);
scena->addItem(this);
}
QRectF CQTank::boundingRect() const
{
qreal adjust = 0.5;
return QRectF(-18 - adjust, -22 - adjust,
36 + adjust, 60 + adjust);
}
QPainterPath CQTank::shape() const
{
QPainterPath path;
path.addRect(-10, -20, 20, 40);
return path;
}
void CQTank::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->setBrush(Qt::yellow);
painter->drawEllipse(-10, -10, 20, 20);
}
I don't know how move an object forward or backward. 我不知道如何向前或向后移动对象。
You have to use the Z-value property, as the docs say: 您必须使用Z值属性,如文档所述 :
void QGraphicsItem::setZValue(qreal z)
无效的QGraphicsItem :: setZValue(qreal z)
Sets the Z-value of the item to z.
将项目的Z值设置为z。 The Z value decides the stacking order of sibling (neighboring) items.
Z值确定同级(相邻)项的堆叠顺序。 A sibling item of high Z value will always be drawn on top of another sibling item with a lower Z value.
Z值较高的同级项将始终被绘制在Z值较低的另一同级项的顶部。
If you restore the Z value, the item's insertion order will decide its stacking order.
如果恢复Z值,则物料的插入顺序将决定其堆叠顺序。
The Z-value does not affect the item's size in any way.
Z值不会以任何方式影响项目的大小。
The default Z-value is 0.
默认的Z值为0。
The larger it is with respect to another one, it will be shown above, otherwise it will be below. 相对于另一个较大,将显示在上方,否则将显示在下方。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.