Jér*_*ôme 5 qt qgraphicsitem qgraphicspixmapitem
我的应用程序正在使用 Qt。
我有一个继承QGraphicsPixmapItem的类。
在这些项目上应用变换(例如,旋转)时,项目的原点(或枢轴点)始终是左上角。
我想改变这个原点,例如,当设置项目的位置时,这实际上会改变像素图的中心。
或者,如果我应用旋转,旋转的原点将是像素图的中心。
我还没有找到一种直接用 Qt 来实现它的方法,所以我想像这样重新实现itemChange():
QVariant JGraphicsPixmapItem::itemChange(GraphicsItemChange Change, const QVariant& rValue)
{
switch (Change)
{
case QGraphicsItem::ItemPositionHasChanged:
// Emulate a pivot point in the center of the image
this->translate(this->boundingRect().width() / 2,
this->boundingRect().height() / 2);
break;
case QGraphicsItem::ItemTransformHasChanged:
break;
}
return QGraphicsItem::itemChange(Change, rValue);
}
Run Code Online (Sandbox Code Playgroud)
我认为这会起作用,因为Qt 的文档提到项目的位置及其变换矩阵是两个不同的概念。
但它不起作用。
任何的想法 ?
| 归档时间: |
|
| 查看次数: |
4282 次 |
| 最近记录: |