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

Change QGraphicsTextItem edit trigger from single click to double click

Scheduled Pinned Locked Moved Solved General and Desktop
qgraphicssceneqtcharts
3 Posts 2 Posters 1.8k 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.
  • M Offline
    M Offline
    martonmiklos
    wrote on 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
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on 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
      1
      • SGaistS SGaist

        Hi,

        What about using mouseDoubleClickEvent ?

        M Offline
        M Offline
        martonmiklos
        wrote on 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

        • Login

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