【问题标题】:QGraphicsEllipseItem not movableQGraphicsEllipseItem 不可移动
【发布时间】:2014-07-28 08:01:54
【问题描述】:

我正在使用 MAC OS X / QT5.3 小部件应用程序,我正在尝试在 QGraphicsItemGroupmovable 中制作 QGraphicsEllipseItem。我正在设置所有需要的标志,但椭圆不会移动。

这是我的代码(省略不重要和简化):

 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);
 }

现在,该点已显示,但不可移动。

【问题讨论】:

  • 里面还有其他可以移动的物品吗?
  • 不,它们都不是。我有点不知所措,因为我知道物品在那里,它们被展示出来,它们在上面,但它们不能移动。
  • 我会尝试使用像素图来确保它不仅仅是细椭圆问题。
  • 请注意,在 GraphicsitemGroup 中“所有子项的所有事件和几何图形都合并在一起”。那么,在将它们添加到组之前,它们是否可以移动?
  • @Merlin069 很棒的思考过程 ;)

标签: c++ qt qgraphicsview


【解决方案1】:

正如Qt documentation 所说:-

QGraphicsItemGroup 类提供了一个将一组项目视为单个项目的容器。

因此,您不应期望在组内移动单个项目。如果要移动整个组,则需要在组本身上设置标志。

由于 QGraphicsItem 和派生类可以作为父类,因此您可以通过创建一个 QGraphicsItem 来实现所需的效果,并将其用作所有想要组合在一起的对象的父类。

这将允许移动单独的图形项成员。

【讨论】:

  • yipee ki kay! :) 这困扰了我很长时间。 :)
猜你喜欢
  • 2014-01-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多