Results 1 to 7 of 7

Thread: Unable to have 2 QGraphicsView getting their own events

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

    Default Unable to have 2 QGraphicsView getting their own events

    I have 1 main QGraphicsView, that has 2 QGraphicsView children. Each of the children has one custom QGraphicsTextItem.
    When I double click on one of the QGraphicsTextItems (whatever the one I am clicking on), I can type letters and they appear properly in it.
    When I then double click the other QGraphicsTextItem, the first one gets the double-click event and the letters.
    If I restart my app and first click on the second QGraphicsTextItem, then the first one will never get focus.

    How can I ensure that the one I am clicking on gets the events ?

    That's the code in each of the QGraphicsView children:
    Qt Code:
    1. myQGraphicsTextItemClass *oneTextNode
    2. oneTextNode=new myQGraphicsTextItemClass(newNodeId,nodeName,this->geometry().width());
    3. oneTextNode->setPos(10,30);
    4. scene()->addItem(oneTextNode);
    To copy to clipboard, switch view to plain text mode 

    And the double click event of the QGraphicsTextItem:
    Qt Code:
    1. void myQGraphicsTextItemClass::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *evt)
    2. {
    3. setTextInteractionFlags(Qt::TextEditorInteraction);
    4. QGraphicsTextItem::mouseDoubleClickEvent(evt);
    5. }
    To copy to clipboard, switch view to plain text mode 

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

    Thanks !

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Unable to have 2 QGraphicsView getting their own events

    Quote Originally Posted by EarthHobbit View Post
    I have 1 main QGraphicsView, that has 2 QGraphicsView children.
    Why?

    Cheers,
    _

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

    Default Re: Unable to have 2 QGraphicsView getting their own events

    I am writing a node editor. Each node is represented by a QGraphicsView. I can potentially have 20 QGraphicsView children or more.
    And the name of the node is displayed on it using a QGraphicsTextItem (must be editable).


    Added after 10 minutes:


    The issue is even actually the same with 2 QGraphicsTextItem in the same QGraphicsView.
    Last edited by EarthHobbit; 18th April 2015 at 14:10.

  4. #4
    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: Unable to have 2 QGraphicsView getting their own events

    Quote Originally Posted by EarthHobbit View Post
    Each node is represented by a QGraphicsView.
    Why?

    Cheers,
    _
    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.


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

    Default Re: Unable to have 2 QGraphicsView getting their own events

    It makes it easier to drag, as I use it as a placeholder for multiple elements.

  6. #6
    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: Unable to have 2 QGraphicsView getting their own events

    What makes it easier to drag than a QGraphicsItem?
    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.


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

    Default Re: Unable to have 2 QGraphicsView getting their own events

    I don't know. Being new to Qt this what I did. Let me check the QGraphicsItem.

Similar Threads

  1. QGraphicsView mouse events
    By high_flyer in forum Qt Programming
    Replies: 22
    Last Post: 29th May 2014, 10:03
  2. Overiding QGraphicsView events with Designer
    By dbrmik in forum Qt Tools
    Replies: 2
    Last Post: 26th July 2011, 09:34
  3. unable to translate QGraphicsView
    By sven-kt in forum Qt Programming
    Replies: 4
    Last Post: 18th January 2010, 17:42
  4. QGraphicsView Mouse Events
    By tomf in forum Qt Programming
    Replies: 5
    Last Post: 29th July 2008, 16:03
  5. Unable to handle WindowStateChange events
    By TheRonin in forum Qt Programming
    Replies: 1
    Last Post: 6th March 2008, 12:20

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.