问题标签 [qgraphicsitem]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
455 浏览

c++ - QGraphicsPolygonItem 从左上角缩放

我有一个关于 QGraphicsPolygonItem 缩放的问题。

我有多边形(在 QGraphicsPolygonItem 内):

然后,我尝试缩放它( setScale(2) ),多边形从中心点开始缩放,而不是从左上角开始。我已阅读有关 Qt 缩放和原点的文档,但没有效果。出于测试目的,我已将多边形更改为矩形 - 比例正常工作。

如何从顶部,左侧缩放多边形?

无比例(红色多边形,黑色矩形):( 来源:sources.ru设置刻度(1)

使用比例 x2:( 来源:sources.ru设置刻度(2)

感谢您的任何帮助

0 投票
1 回答
842 浏览

c++ - Qt C++ Let multiple QGraphicsItem handle one mouse event

I've created an object Chartblock that implements QGraphicsItem. My goal is to create a grid of these objects, and when the mouse button is pressed (and held) and is drug over each block, perform something on each block as the cursor enters it.

Since a QGraphicsItem grabs the mouse events when it is clicked within it, other Items will not fire for the mouseMoveEvent. I then created an object based on the QGraphicsItemGroup to handle all the mouse events, but then I would need some way to pass mousePressEvent/mouseReleaseEvent as well as mouseMoveEvent to each child that the cursor is over.

Am I overthinking how to do this? It seems like such a simple action shouldn't be that difficult to create, but with QGraphicsItems holding onto the mouse events for itself, I'm not sure how to get around it. I've read similar situations, but nothing seems to give a straightforward answer.

Edit: I suppose a way to do this would keep track of the coordinates/sizes of every single QGraphicsItem I create in an array, then get the position of the cursor in the Group mouseMoveEvent, and see if there's a hit..

0 投票
1 回答
661 浏览

qt - QGraphicsRectItem 上的drawForeground

我需要一种方法QGraphicsRectItem来绘制它的孩子。我有一个包含几个子项目的项目。在特定高度,我需要在子项目上画一条线。

有没有办法实现 a drawForegroundinQGraphicsItems类似于drawForegroundin QGraphicsScene

如果可能的话,我宁愿不必为每个子项目画线。

0 投票
1 回答
787 浏览

qt - QT +如何禁用QGraphicssvgitem的边界矩形?

我想知道如何禁用/隐藏boundingrectangle.QGraphicssvgitem

这适用于 if not implement QGraphicsitem::Itemisselectable,但如果没有实现,那么我在调用mouserelease事件时遇到问题。所以请帮助我 强文本

好的..我目前正在开发一个使用单线图设计软件QT的系统。多数民众赞成的主要特点之一是拖放。左侧我有一个QDockwidget。有QGraphicssvgitems。这些东西将被拖到 QGraphicsscene 中。当 QGraphicssvgitem 下降到 QGraphicsscene 时,现在项目周围显示虚线,这是我遇到的问题。如果我实现(QGraphicsitem::Itemisselectable,false) ,这条虚线就会关闭。如果这实现了我的 svgitem 将无法正确卡入 QGraphicsscene 的网格。有没有其他方法可以关闭项目周围的这个虚线边界矩形?

0 投票
2 回答
13872 浏览

c++ - 运行时检查失败 #0 - ESP 的值未在函数调用中正确保存

我创建了一个简单的程序来演示我在使用多重继承的 Qt 应用程序中遇到的运行时错误。继承树如下所示:

这是代码:

调用我的接口方法时,在 Visual Studio 中进行调试会导致运行时错误:

知道问题是什么吗?

0 投票
3 回答
1939 浏览

qt - 在 QGraphicsItem(父级)中绘制形状,其位置相对于父级

我有我自己的对象实现QGraphicsItem- 它本质上只是一个带边框的正方形。我正在尝试在该项目中绘制形状,将其用作父项。问题是我用于父级中的形状的坐标不是相对于父级的坐标,而是相对于场景。

示例:我想QGraphicsLineItem在我QGraphicsItem的(父母)内画一个。父级为 50,50,尺寸为 20x20。如果我使用指定的父级绘制一条线,使用坐标 0,0,20,20,它会在相对于场景而不是父级的 0,0,20,20 处绘制。

有没有办法让线条(或任何其他形状)使用相对于父级而不是场景的位置?或者我是否需要通过检查父母的 X 和 Y 来手动确定坐标?

0 投票
2 回答
600 浏览

c++ - 将自己的对象放入 QGraphicsScene

我想有一个基于图像的拖放功能。如果我拖放一个图像,我想知道我选择并移动了哪个图像(一个简单的 std::string 可以唯一标识该图像所代表的对象)。我的想法是将我自己的对象(QPixmapItem)存储在 QGraphicsScene 中:

这是我用来将对象添加到场景中的方法:

这是我尝试在 QMouseEvent 中“捕获”对象的方法:

对象被添加到场景中,但每当我按下它们时,最后一行(“按下的项目”)永远不会出现在屏幕上。

0 投票
4 回答
7267 浏览

qt - QGraphicsItem 选择

是否存在一个简单的方法来选择 QGraphicsItem 的一部分(例如选择,例如带有虚线边框),尽管它在QGraphicsScene

我找到QGraphicsItem::ItemIsSelectable了,但对我帮助不大。

谢谢

0 投票
1 回答
472 浏览

qt - 重绘 QGraphicsItem 时重新定义 QPainter 选项

我想在 QGraphics 场景中绘制每个 QGraphicsItem 之前重新定义 QPainter。

现在已经过时了,什么是“新”方法?

谢谢

0 投票
1 回答
2839 浏览

qt - 在 Qt 中绘制多色线

我想要实现的是以下内容:我有QGraphicsScene一个QGraphicsPixmapItem显示在其中的。像素图有多种颜色,我需要在像素图上画一条线,该线必须在每个点上都可见且可识别。

我的想法是画一条线,其中每个像素都具有像素图相对像素的负(互补)颜色。所以我想到了子类QGraphicsItem化并重新实现paint()绘制多色线的方法。

但是我被卡住了,因为我不知道如何从paint函数中检索像素图的像素信息,即使我发现了,我也想不出用这种方式画线的方法。

你能给我一些关于如何进行的建议吗?