如何在不选择整个组(该项目所属)的情况下选择 QGraphicsItem

发布于 2024-09-29 05:53:37 字数 346 浏览 2 评论 0原文

我想知道是否可以选择属于一组的项目,而不选择整个组。

我试图制作的是一组可以移动的项目(所有项目都一起移动),但没有一个项目不能单独移动。但我还希望能够选择该组内的项目,然后对它们执行某些操作,例如重新排序、删除、更改其颜色等。

另一个问题是,可以有一组组。我还希望能够在父组中选择这些组。我认为这可能是个问题,因为我们无法确定用户想要选择哪个组。为了演示目的,假设我们有由以下项目组成的图形场景:

A 组包含 B 组。B 组包含 3 条线。 如果我双击 A 组,则可以选择 B 组。如果我再次双击 B,则可以选择 B 组内的行。按 Esc 与双击相反。问题是,我不知道该怎么做,因为所有选择都路由到父母,然后返回到所有孩子。

I wonder if it is possible to select item that belongs to one group, without selecting whole group.

What I trying to make is a group of items, that can be moved (all items are moved together) but none of them can't be moved individually. But I want also to be able to select items inside this group and then do something with them, like reordering, deleting, changing their color, etc.

The other problem is, there can be group of groups. I wish also to be able to select these groups inside parent group. I was thinking that this could be problem, because we are not able to determine which group users want to select. For demonstration purpose, lets say that we have graphic's scene composed of following items:

Group A which contains group B. The group B contains 3 lines.
If I press double click on group A, then I am then able to select group B. If I again press double click on B, then I am able to select lines inside group B. Pressing Esc does opposite as double click. The problem is, I have no idea how to do that, because all selection is routed to the parents, and than back to all its children.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

听,心雨的声音 2024-10-06 05:53:37

您不能使用 QGraphicsItemGroup 来执行此操作,因为选择组中的一项会自动选择该组的所有其他成员。

我将 QGraphicsItem 子类化以创建“RootItem”类。这个类将包含两个列表。一个是普通 QGraphicsItems 的列表,它们构成组本身的视觉元素,是该 RootItem 的父级。另一个列表是与该 RootItem 相关的其他 RootItem(例如 Group B)。

您只需要确保仔细控制哪些项目可以随时选择以及交互如何在项目之间传播。

希望这有帮助。

You can't use QGraphicsItemGroup to do this because selecting one item in a group automaticaly selects all other memebrs of the group.

I'd subclass QGraphicsItem to create a 'RootItem' class. This class would contain two lists. One is a list of ordinary QGraphicsItems that make up the visual elements of the group itself, parented to this RootItem. The other list is of other RootItems that are parented to this one (e.g. Group B).

You would just need to make sure that you carefully controlled which items are selectable at any one time and how the interactions propagate between items.

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文