I've made a program with PyQt5. I have a main window containing a QGraphicsScene within a QGraphicsView. I have an editable QGraphicsTextItem in the scene as follows.
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QMainWindow, QGraphicsView, QGraphicsScene, QHBoxLayout, QWidget, QApplication, QGraphicsTextItem
class Window(QMainWindow):
def __init__(self):
super(Window, self).__init__()
self.scene = QGraphicsScene()
self.graphicsview = QGraphicsView(self.scene)
self.layout = QHBoxLayout()
self.layout.addWidget(self.graphicsview)
self.setCentralWidget(QWidget())
self.centralWidget().setLayout(self.layout)
self.resize(500, 500)
self.graphicsview.show()
self.show()
textitem = QGraphicsTextItem("Test")
textitem.setTextInteractionFlags(Qt.TextEditorInteraction)
self.scene.addItem((textitem))
def main():
app = QApplication(sys.argv)
window = Window()
sys.exit(app.exec())
main()
The problem is that the program crashes if the right mouse button is clicked within the textitem's area in the scene. The textitem and the text editor work fine as long as the right mouse button is not being clicked upon the item.
If I don't set the TextEditorInteraction, the right mouse button don't cause any problems.
I've tried using setAcceptedMouseButtons() -method to only allow left mouse button clicks on the item, but it has not had any effect. Not sure if I got the syntax right though.
I've tried to find a fix to this problem for quite a while now, but nothing has worked so far.