TypeError: arguments did not match any overloaded call: mapToScene(self, point: QPoint): argument 1 has unexpected type 'QPointF' mapToScene(self, rect: QRect): argument 1 has unexpected type 'QPointF' mapToScene(self, polygon: QPolygon): argument 1 has unexpected type 'QPointF' mapToScene(self, path: QPainterPath): argument 1 has unexpected type 'QPointF' mapToScene(self, ax: int, ay: int): argument 1 has unexpected type 'QPointF' mapToScene(self, ax: int, ay: int, w: int, h: int): argument 1 has unexpected type 'QPointF
时间: 2024-04-04 20:29:12 浏览: 20
这是一个类型错误,mapToScene方法的参数应该是QPoint类型的对象,而实际传入的是QPointF类型的对象,因此引发了类型错误。QPointF是QPoint的浮点数版本,二者并不兼容。可以通过将QPointF对象转换为QPoint对象来解决这个问题,例如:
```
pScene = self.graphics_view.mapToScene(QPoint(int(pos.x()), int(pos.y())))
```
这里使用int()函数将QPointF对象中的浮点数坐标值转换为整数类型,生成一个QPoint对象作为mapToScene方法的参数。这样就可以避免这个类型错误了。
相关问题
TypeError: arguments did not match any overloaded call: setSceneRect(self, rect: QRectF): argument 1 has unexpected type 'QRect' setSceneRect(self, x: float, y: float, w: float, h: float): argument 1 has unexpected type 'QRect'
这个错误是由于调用setSceneRect()函数时,传入的参数类型不正确导致的。setSceneRect()函数有两个重载,一个接受QRectF类型的参数,另一个接受四个浮点数类型的参数。因此,如果传递了一个QRect类型的参数,它会引发TypeError。
要解决此问题,您可以将QRect类型的参数转换为QRectF类型的参数。您可以使用QRectF的构造函数或QRect的toRectF()方法来完成此操作。例如:
```python
# Convert QRect to QRectF
rect = QRect(0, 0, 100, 100)
rectf = QRectF(rect)
# Or using toRectF() method
rect = QRect(0, 0, 100, 100)
rectf = rect.toRectF()
# Now you can pass rectf to setSceneRect() function
self.scene().setSceneRect(rectf)
```
在这个示例中,我们首先定义一个QRect类型的矩形,然后使用QRectF的构造函数将其转换为QRectF类型的矩形。或者,我们可以使用QRect的toRectF()方法来完成此操作。最后,我们将QRectF类型的矩形传递给setSceneRect()函数。
这样,您就可以将QRect类型的参数转换为QRectF类型的参数,并解决TypeError错误。
TypeError: arguments did not match any overloaded call: display(self, str: str): argument 1 has unexpected type 'method' display(self, num: float): argument 1 has unexpected type 'method' display(self, num: int): argument 1 has unexpected type 'method'
这个错误提示意味着你调用了一个名为 `display` 的方法,但它的参数类型与定义的不匹配。这里的错误是因为你传递给 `display` 方法的参数类型不正确,应该传递字符串、浮点数或整数类型的参数。
例如,如果你定义了一个类 `MyClass`,其中包含一个名为 `display` 的方法,该方法接受一个字符串参数并将其打印到控制台上。你可以按照以下方式调用该方法:
```python
class MyClass:
def display(self, message):
print(message)
my_obj = MyClass()
my_obj.display("Hello, world!")
```
输出结果应该是:
```
Hello, world!
```
请确保你调用 `display` 方法时传递正确类型的参数,这样就可以避免这种类型的错误。