Results 1 to 2 of 2

Thread: Enable editing by double clicking QGraphicsTextItem

  1. #1
    Join Date
    Jul 2012
    Posts
    53
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Enable editing by double clicking QGraphicsTextItem

    Hi,
    I'm want to enable the text editing mode of QGraphicsTextItem when double clicking the item.
    I tried to directly set the setTextInteractionFlags(Qt::TextEditorInteraction), but this enables editing mode by single clicking.

    I also tried to override the mouseDoubleClickEvent event of QGraphicsTextItem, as the code below. However the text in item is not editable immediately after double clicking. I have to click the text once more to edit the text.

    Qt Code:
    1. void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event){
    2. setTextInteractionFlags(Qt::TextEditorInteraction);
    3.  
    4. QGraphicsTextItem::mouseDoubleClickEvent(event);
    5. }
    6. void focusOutEvent(QFocusEvent * event){
    7. setTextInteractionFlags(Qt::NoTextInteraction);
    8. QGraphicsTextItem::focusOutEvent(event);
    9. }
    To copy to clipboard, switch view to plain text mode 

    Is there a better way to enable editing by double clicking?
    Any suggestions are welcome.
    Thanks.

    ----------Update----------
    Just found an example in Qt emamples called "Diagramscene". In the file diagramtextitem.cpp, they use almost the same method as mine and cause the same problem.
    Futhermore, if you double click the text and then out of focus directly, the text is still keep selected and is able to edit after single click it. Is this a feature or bug?
    Last edited by Seishin; 6th November 2012 at 20:31.

  2. #2
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Enable editing by double clicking QGraphicsTextItem

    Have a look at my answer in a similar thread, it should contain what you're searching for:

    Re: QGraphicsTextItem and text cursor position via QPoint

Similar Threads

  1. Double Clicking Pro File
    By BalaQT in forum Installation and Deployment
    Replies: 2
    Last Post: 18th November 2009, 05:23
  2. enable user editing of QTreeView headers?
    By iraytrace in forum Newbie
    Replies: 0
    Last Post: 9th October 2009, 22:25
  3. QListView icon double clicking
    By been_1990 in forum Qt Programming
    Replies: 8
    Last Post: 28th April 2009, 20:05
  4. Double clicking with QTableView
    By DPinLV in forum Qt Programming
    Replies: 2
    Last Post: 13th September 2006, 06:22
  5. QTableView - Enable Clicking for some columns only
    By Gabriel in forum Qt Programming
    Replies: 1
    Last Post: 23rd June 2006, 22:42

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.