PySide6 Code without errors but not working

48 views Asked by At

I'm creating an engineering-oriented desktop application, i want to create an interface where it is possible to drag piping items, as well as other accessories (later), and thus set up a pneumatic network.

To do this, I'm using PySide6 and PyCharm. Apparently the IDE did not point out any errors, the code runs normally without pointing out errors either, however, nothing opens on the screen and the following message Process finished with exit code -1073741819 (0xC0000005) appears.

Furthermore, something like a message is appearing on line 12 and 16 in PyCharm itself, which I don't know if it is related to this problem and which is also bothering me because I don't know what it is.

Overrides method in QGraphicsRectItem -> def paint(self, painter: QPainter, option, widget=None):

Overrides method in QGraphicsItem -> def itemChange(self, change, value):

Below is the entire code:

from PySide6.QtWidgets import QGraphicsScene, QGraphicsView, QGraphicsItem, QGraphicsRectItem, QApplication
from PySide6.QtGui import QPainter

class PipeItem(QGraphicsRectItem):
    def __init__(self, scene_width, scene_height):
        super(PipeItem, self).__init__(-50, -2.5, 100, 5)
        self.setFlag(QGraphicsItem.ItemIsMovable)
        self.setFlag(QGraphicsItem.ItemIsSelectable)
        self.scene_width = scene_width
        self.scene_height = scene_height

    def paint(self, painter: QPainter, option, widget=None):
        super().paint(painter, option, widget)
        painter.drawLine(0, 0, 100, 100)

    def itemChange(self, change, value):
        if change == QGraphicsItem.ItemPositionChange or change == QGraphicsItem.ItemPositionHasChanged:
            new_pos = value.toPointF()
            new_pos.setX(max(new_pos.x(), -self.scene_width/2))
            new_pos.setX(min(new_pos.x(), self.scene_width/2))
            new_pos.setY(max(new_pos.y(), -self.scene_height/2))
            new_pos.setY(min(new_pos.y(), self.scene_height/2))
            return new_pos

        return super(PipeItem, self).itemChange(change, value)

# Configuração da cena e da visualização
scene_width, scene_height = 800, 600
scene = QGraphicsScene(-scene_width/2, -scene_height/2, scene_width, scene_height)
view = QGraphicsView(scene)

# Criar item de tubulação e adicionar à cena
pipe_item = PipeItem(scene_width, scene_height)
scene.addItem(pipe_item)

# Exibir a visualização
view.show()

# Executar o aplicativo
app = QApplication([])
app.exec_()

I really tried to look for the reason for the error, and I couldn't find it. I would appreciate it if someone is willing to help me find a solution to this, and explain to me what the problem is, so I can avoid it in the future.

0

There are 0 answers