QGraphicsEllipseItem不可移动
QGraphicsEllipseItem not movable
本文关键字:可移动 QGraphicsEllipseItem 更新时间:2023-10-16
我正在MAC OS X/QT5.3小部件应用程序中工作,我正试图使QGraphicsEllipseItem
在QGraphicsItemGroup
中移动。我正在设置所有需要的标志,但是椭圆不会移动。
下面是我的代码(省略了不重要的和简化的):
QGraphicsView * view;
QGraphicsItemGroup * controlPoints;
//there are more groups
void setUp()
{
view = new QGraphicsView();
view->setRenderHint(QPainter::Antialiasing,true);
QGraphicsScene * scene = new QGraphicsScene(0,0,500,500);
view.setScene(scene);
controlPoints = new QGraphicsItemGroup();
//there are multiple groups and i need them to be in different depths(zvalues)
controlPoints->setZValue(2);
scene.addItem(controlPoints);
}
void AddPointsToGroup()
{
QGraphicsEllipseItem * controlPoint = new QGraphicsEllipseItem(100,100,6.5,6.5);
controlPoint->setFlag(QGraphicsItem::ItemIsMovable,true);
controlPoint->setFlag(QGraphicsItem::ItemIsSelectable,true);
controlPoint->setFlag(QGraphicsItem::ItemIsFocusable,true);
controlPoint->setFlag(QGraphicsItem::ItemSendsGeometryChanges);
controlPoints->addToGroup (controlPoint);
}
现在,这个点已经显示出来了,但是不能移动
正如Qt文档所述:-
QGraphicsItemGroup类提供了一个容器,它将一组项视为单个项。
因此,您不应该期望在组中移动单个项。如果你想移动组作为一个整体,你需要设置组本身的标志。
由于QGraphicsItem和派生类可以是父类,您可以通过创建单个QGraphicsItem来实现所需的效果,您可以将该QGraphicsItem用作所有您想要组合在一起的类的父类。
这将允许移动单独的图形项成员。
相关文章:
- 仅包含可移动 std::map 的类的移动构造函数不起作用
- 为什么协程的返回类型必须是可移动构造的?
- 我应该使我的局部变量常量还是可移动的
- 对于参加可复制和可移动类的访问者来说,应该有多少过载?
- 如何获取类型是否真正可移动可构造
- 可移动但不可复制的对象:按值传递还是按引用传递?
- 对于可移动类型,按值传递比重载函数更好吗?
- 使用参数将仅可移动对象捕获到 lambda
- 具有抑制移动构造/赋值的类型如何仍被视为可移动类型?
- 防止作用域枚举可复制/可移动
- 禁止可移动的QGraphics物品与其他物品发生冲突
- 在向量中使用派生的可移动但不可压缩的会导致编译错误
- 在可移动类型的构造函数 lambda 中捕获此内容的安全使用
- 从类返回可移动成员变量
- 在成员容器中复制具有仅可移动但可克隆类型的构造函数
- 不可复制但可移动的容器
- 可移动但不可复制的异常
- 具有可移动节点、可访问属性和可靠ID的C++图
- 使用不可复制(但可移动)键移动地图分配时出错
- C++11/VS2010:返回包含不可复制但可移动对象的容器