QGraphicsItem取消选择重绘问题

发布于 2024-08-07 18:24:14 字数 343 浏览 7 评论 0原文

非常简单的 Qt GUI 应用程序:

  • 在场景中,我实现了多个圆圈,因为 QGraphicsItemboundingRect
  • 返回周围的正方形 这个圈子。
  • 方法“shape”未被覆盖。

在我添加的 Paint() 方法中出现问题:

if (isSelected()) {
    painter->drawRect(re);
}

选择绘制良好,但取消选择不会导致重绘。在日志级别我可以看到该项目确实丢失了选择标志。 从 itemChange 调用 update() 也是无用的。 预先感谢您的任何建议。

Very simple Qt GUI application:

  • On the scene I have multiple circles implemented as QGraphicsItem
  • boundingRect returns square around
    this circle.
  • Method 'shape' is not overridden.

The problem appears when in paint() method I've added:

if (isSelected()) {
    painter->drawRect(re);
}

Selection is drawn well, but unselection doesn't cause redrawing. At log level I can see that item really lost selection flag.
Calling update() from itemChange is useless also.
Thank you in advance for any suggestion.

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

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

发布评论

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

评论(2

扛起拖把扫天下 2024-08-14 18:24:14

10天后,我回到这个问题,发现我的 QGraphicsItem 是用
setCacheMode(DeviceCooperativeCache);
我的天啊!愚蠢的错误,当这条线被删除时(默认使用 QGraphicsItem::NoCache),选择会被重新绘制得很好。

After 10 days I returned back to this problem and discovered that my QGraphicsItem constructed with
setCacheMode(DeviceCoordinateCache);
OMG! Stupid mistake, when this line was removed (by default QGraphicsItem::NoCache used) selection is redrawn well.

惜醉颜 2024-08-14 18:24:14

您还可以尝试使用 setViewportUpdateMode(QGraphicsView::FullViewportUpdate) 将默认的 QGraphicsView::MinimalViewportUpdate 更改为 FullViewportUpdate;

或者你可以调用 scene()->update();从项目中安排重新绘制。

至少当我不断更改项目上的 QGraphicsItem::ItemHasNoContents 标志时,其中之一是必需的。

You can also try to change the default QGraphicsView::MinimalViewportUpdate to FullViewportUpdate with setViewportUpdateMode(QGraphicsView::FullViewportUpdate);

Or you can call scene()->update(); from the item to schedule a repaint.

One of them was required at least when I kept changing the QGraphicsItem::ItemHasNoContents flag on an item.

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