Unable to modify QGraphicsTextItem text contents interactively
-
I have individual subclass for QGraphicsView, QGraphicScene and QGraphicTextItem. I have added 'QGraphicTextItem' subclass object to scene and called the function setTextInteractionFlags(Qt::TextEditorInteraction).
But, I am unable to edit the text content. I feel like keyboard inputs are not honored by my sub-classes. I added debug statement in keyPressEvent() functions in subclass of QGraphicsView and QGraphicTextItem but they are not executedLater, I have tried with actual Qt class (not my subclass). It works fine. What changes needed in sub-classes to get events from keyboard ?
-
@Sridharan
The code shown adds aQGraphicsTextItem. You said your problem arises when you subclassQGraphicsTextItem. Are we to presume your actual code usesYourGraphicsTextItem textItem("Text data")to create the item?And this code is not what is needed when overriding a method, it does not show the base class method being called from the subclass's override.
So... unless you show the actual code you are using in your subclass overridden methods we cannot say if you are doing it right. Certainly if it is as shown it is quite wrong.
-
Hi,
Without any code it's hard to tell. One of the usual suspect: are you calling the base class implementation of the methods you override ?
-
Hi,
Without any code it's hard to tell. One of the usual suspect: are you calling the base class implementation of the methods you override ?
@SGaist
Yes, I call base class implementation.QGraphicsTextItem textItem("Text data");
textItem.setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsFocusable);
textItem.setTextInteractionFlags(Qt::TextEditorInteraction);And I have added this text item to scene
-
@SGaist
Yes, I call base class implementation.QGraphicsTextItem textItem("Text data");
textItem.setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsFocusable);
textItem.setTextInteractionFlags(Qt::TextEditorInteraction);And I have added this text item to scene
@Sridharan
The code shown adds aQGraphicsTextItem. You said your problem arises when you subclassQGraphicsTextItem. Are we to presume your actual code usesYourGraphicsTextItem textItem("Text data")to create the item?And this code is not what is needed when overriding a method, it does not show the base class method being called from the subclass's override.
So... unless you show the actual code you are using in your subclass overridden methods we cannot say if you are doing it right. Certainly if it is as shown it is quite wrong.
-
@Sridharan
The code shown adds aQGraphicsTextItem. You said your problem arises when you subclassQGraphicsTextItem. Are we to presume your actual code usesYourGraphicsTextItem textItem("Text data")to create the item?And this code is not what is needed when overriding a method, it does not show the base class method being called from the subclass's override.
So... unless you show the actual code you are using in your subclass overridden methods we cannot say if you are doing it right. Certainly if it is as shown it is quite wrong.