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. Change QGraphicsTextItem edit trigger from single click to double click
Forum Update on Monday, May 27th 2025

Change QGraphicsTextItem edit trigger from single click to double click

Scheduled Pinned Locked Moved Solved General and Desktop
qgraphicssceneqtcharts
3 Posts 2 Posters 1.5k Views
  • 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.
  • M Offline
    M Offline
    martonmiklos
    wrote on 21 Sept 2018, 16:51 last edited by martonmiklos
    #1

    I am working on a patch for the QtCharts module (https://codereview.qt-project.org/#/c/239957) which main goal is making chart labels (QGrapcshiTextItems) editable.

    I can easily enable the editing of the QGraphicsTextItem with the QGraphicsTextItem::setTextInteractionFlags, but by default a single click will enable the edit mode.

    The reviewers asked me to change this behavior to double click.

    I have tried to ignore the event in the reimplemented mousePressEvent, but the single click still triggers the editing.

    Any other idea would be welcome!

    1 Reply Last reply
    1
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 21 Sept 2018, 20:06 last edited by
      #2

      Hi,

      What about using mouseDoubleClickEvent ?

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

      M 1 Reply Last reply 22 Sept 2018, 21:16
      1
      • S SGaist
        21 Sept 2018, 20:06

        Hi,

        What about using mouseDoubleClickEvent ?

        M Offline
        M Offline
        martonmiklos
        wrote on 22 Sept 2018, 21:16 last edited by
        #3

        @SGaist

        Hi Sam,

        Thank you for your hint, but my first problem was preventing the edit trigger on single click.

        For the posterity I have ended up with the following solution:

        • Disable the textInteraction flags by default
        • Override the QGraphicsTextItem::sceneEvent with the following:
        bool ValueAxisLabel::sceneEvent(QEvent *event)
        {
            if (event->type() == QEvent::GraphicsSceneMouseDoubleClick) {
                setTextInteractionFlags(Qt::TextEditorInteraction);
        
                bool ret = QGraphicsTextItem::sceneEvent(event);
                // QGraphicsTextItem::sceneevent needs to be processed before
                // the focus
                setFocus(Qt::MouseFocusReason);
                return ret;
            }
            return QGraphicsTextItem::sceneEvent(event);
        }
        

        The textInteractionFlags should be disabled in the overridden focusOutEvent.

        1 Reply Last reply
        1

        3/3

        22 Sept 2018, 21:16

        • Login

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