Results 1 to 2 of 2

Thread: QGraphicsTextItem always gets focus once clicked

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2015
    Posts
    12
    Thanks
    1
    Qt products
    Qt5
    Platforms
    MacOS X

    Default QGraphicsTextItem always gets focus once clicked

    I have a QGraphicsView containing a custom QGraphicsTextItem. The QGraphicsTextItem has a double-click event:

    Qt Code:
    1. void myQGraphicsTextItemClass::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *evt)
    2. {
    3. MGlobal::displayInfo(MQtUtil::toMString(QString().sprintf("Double click on textId")));
    4.  
    5. QGraphicsTextItem::mouseDoubleClickEvent(evt);
    6. }
    To copy to clipboard, switch view to plain text mode 
    What goes well:
    When I double click in the QGraphicsView but not in the QGraphicsTextItem, then nothing happens, which is normal. When I double click directly on the QGraphicsTextItem, then I get a "Double click on textId" message, as expected.

    What goes wrong:
    However when I then double click again wherever on my main QGraphicsView but not in the QGraphicsTextItem, then I always get the above message.

    Question:
    How come the QGraphicsTextItem keeps getting the mouseDoubleClickEvent events even if I am not directly clicking on it ?

    My QGraphicsTextItem is created this way from the QGraphicsView constructor:

    Qt Code:
    1. oneTextNode=new myQGraphicsTextItemClass();
    2. scene()->addItem(oneTextNode);
    To copy to clipboard, switch view to plain text mode 
    and my QGraphicsTextItem class looks like:

    Qt Code:
    1. class myQGraphicsTextItemClass : public QGraphicsTextItem
    2. {
    3. Q_OBJECT
    4. public:
    5. myQGraphicsTextItemClass(QGraphicsItem *parent=0);
    6. virtual ~myQGraphicsTextItemClass() {};
    7. protected:
    8. virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *evt);
    9. };
    To copy to clipboard, switch view to plain text mode 
    and its constructor:

    Qt Code:
    1. myQGraphicsTextItemClass::myQGraphicsTextItemClass(QGraphicsItem *parent) : QGraphicsTextItem ( parent )
    2. {
    3. setPlainText("Hello");
    4. setTextInteractionFlags(Qt::TextEditorInteraction);
    5. }
    To copy to clipboard, switch view to plain text mode 
    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsTextItem always gets focus once clicked

    Please provide a minimal compilable example reproducing the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 51
    Last Post: 26th November 2010, 14:24
  2. Window focus issues (How to force focus to a window?)
    By montylee in forum Qt Programming
    Replies: 3
    Last Post: 25th April 2009, 02:00
  3. QGraphicsTextItem focus problem
    By Gopala Krishna in forum Qt Programming
    Replies: 5
    Last Post: 26th June 2007, 18:25
  4. Focus issues / Setting multiple focus
    By ComputerPhreak in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2007, 07:09
  5. QGraphicsTextItem - is it a bug there?
    By Tair in forum Qt Programming
    Replies: 5
    Last Post: 18th October 2006, 09:48

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.