Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Unable to modify QGraphicsTextItem text contents interactively
Forum Updated to NodeBB v4.3 + New Features

Unable to modify QGraphicsTextItem text contents interactively

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 584 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sridharan
    wrote on last edited by Sridharan
    #1

    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 executed

    Later, I have tried with actual Qt class (not my subclass). It works fine. What changes needed in sub-classes to get events from keyboard ?

    1 Reply Last reply
    0
    • JonBJ JonB

      @Sridharan
      The code shown adds a QGraphicsTextItem. You said your problem arises when you subclass QGraphicsTextItem. Are we to presume your actual code uses YourGraphicsTextItem 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.

      S Offline
      S Offline
      Sridharan
      wrote on last edited by
      #5

      @JonB
      [Solved]
      In my GraphicsView constructor, setFocusPolicy(Qt::NoFocus) is set. After changing it to Qt::StrongFocus, it worked

      1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        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 ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        S 1 Reply Last reply
        0
        • SGaistS SGaist

          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 ?

          S Offline
          S Offline
          Sridharan
          wrote on last edited by
          #3

          @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

          JonBJ 1 Reply Last reply
          0
          • S Sridharan

            @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

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #4

            @Sridharan
            The code shown adds a QGraphicsTextItem. You said your problem arises when you subclass QGraphicsTextItem. Are we to presume your actual code uses YourGraphicsTextItem 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.

            S 1 Reply Last reply
            0
            • JonBJ JonB

              @Sridharan
              The code shown adds a QGraphicsTextItem. You said your problem arises when you subclass QGraphicsTextItem. Are we to presume your actual code uses YourGraphicsTextItem 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.

              S Offline
              S Offline
              Sridharan
              wrote on last edited by
              #5

              @JonB
              [Solved]
              In my GraphicsView constructor, setFocusPolicy(Qt::NoFocus) is set. After changing it to Qt::StrongFocus, it worked

              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved