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. [Completely solved] QGraphicsTextItem: Howto start editing via code?
Qt 6.11 is out! See what's new in the release blog

[Completely solved] QGraphicsTextItem: Howto start editing via code?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.4k 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.
  • A Offline
    A Offline
    Asperamanca
    wrote on last edited by
    #1

    How do I start text editing via code for those QTextDocument based classes?

    Based on my experiments with QGraphicsTextEdit, the obvious attempt was to use setFocus. However, while I get the nice frame that indicates editing, and also a blinking cursor, I cannot type until I actually click into the widget using the mouse.

    How to do it? Of course, I can simulate a mouse click, but that sounds ugly.

    EDIT: I have since found that in a very simple test sample, setFocus works. So something in my environment seems to block me.

    EDIT2: Apparently, a QPushButton is soaking up the key press events. How I just have to find out why it's doing that, although I clearly have set the focus elsewhere.

    EDIT3: Setting the focus on a QGraphicsItem does not automatically cause it to receive keyboard events, because one of the QGraphicsViews showing this item must receive the keyboard focus, too.

    1 Reply Last reply
    0
    • W Offline
      W Offline
      WoJo
      wrote on last edited by
      #2

      have you tried this:

      @QWidget *w = QApplication::focusWidget();
      if(w) w->clearFocus();
      // set your focus
      @

      "QApplication::focusWidget()":http://qt-project.org/doc/qt-4.8/qapplication.html#focusWidget

      bq. Returns the application widget that has the keyboard input focus, or 0 if no widget in this application has the focus.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Asperamanca
        wrote on last edited by
        #3

        No, I haven't. But it now appears logical to me that a QGraphicsItem cannot know which of the views displaying it should receive the focus. Therefore, setFocus on a QGraphicsItem alone does not contain enough information to determine the focusWidget.

        1 Reply Last reply
        0

        • Login

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