Results 1 to 7 of 7

Thread: Sending event from child widget

  1. #1
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Sending event from child widget

    Dear Qt workers,

    Working with QGraphicsView, I managed an overlayed child QWidget attached to the mouse.
    Since I need to control my view from the mouse, I catch events in the widget then I can call slots by emitting signals.

    But my problem is to transmit mouse events to QGraphicsItem, for instance to take benefit of default selecting and moving, or change item state by double clicking.
    Mouse event cannot reach items, event if I write :
    Qt Code:
    1. void QCursorView::mouseDoubleClickEvent(QMouseEvent * event) {
    2. QWidget::mouseDoubleClickEvent(event);
    3. QMouseEvent translatedEvent(event->type(),
    4. mapTo(parentWidget(), event->pos()),
    5. event->button(),
    6. event->buttons(),
    7. event->modifiers());
    8. qApp->sendEvent(parentWidget(), &translatedEvent);
    9. }
    To copy to clipboard, switch view to plain text mode 
    Neither the view receive the event.

    What is the way to send events properly?
    Is there any restriction according to widget hierarchy and event calling stack?

    Thanks by advance

    PS: I cannot use Qt::WA_TransparentForMouseEvents since I need to do some computation in the child widget in response of some events.
    since

    S.Cascio

  2. #2
    Join Date
    Dec 2008
    Location
    TaganrogNativelandChehov,Russia
    Posts
    64
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sending event from child widget

    why you are writing this order:
    Qt Code:
    1. QWidget::mouseDoubleClickEvent(event);
    2. QMouseEvent translatedEvent(event->type(),
    3. mapTo(parentWidget(), event->pos()),
    4. event->button(),
    5. event->buttons(),
    6. event->modifiers());
    7. qApp->sendEvent(parentWidget(), &translatedEvent);
    To copy to clipboard, switch view to plain text mode 

    why not

    Qt Code:
    1. QMouseEvent translatedEvent(event->type(),
    2. mapTo(parentWidget(), event->pos()),
    3. event->button(),
    4. event->buttons(),
    5. event->modifiers());
    6. qApp->sendEvent(parentWidget(), &translatedEvent);
    7. QWidget::mouseDoubleClickEvent(event);
    To copy to clipboard, switch view to plain text mode 
    why you are calling
    QWidget::mouseDoubleClickEvent(event);
    at all?
    east or west home is best

  3. #3
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sending event from child widget

    Thanks for your time.

    The code provided is in the child widget and I need to transmit the event to the parent widget with mouse coordinates transformed.
    So, calling base class and sendEvent are not working on same object. So instructions are independant, aren't they?

    Calling the base class is just a reflex.

  4. #4
    Join Date
    Dec 2008
    Location
    TaganrogNativelandChehov,Russia
    Posts
    64
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sending event from child widget

    Quote Originally Posted by scascio View Post
    Thanks for your time.
    So instructions are independant, aren't they?
    I think no. It is in dependences.
    try to comment this line.
    Qt Code:
    1. QWidget::mouseDoubleClickEvent(event);
    To copy to clipboard, switch view to plain text mode 
    east or west home is best

  5. #5
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sending event from child widget

    It does not work.
    Commented or not, before or after. Same result : event is not transmitted to parent view, so neither to item.

    I tried to ignore event without success.

    The only way I can make it work is to emit signals and catch them into slots.
    But then I must rewrite basic features of QGraphicsView, such as clicking an item to select it, anywhere to unselect, moving items, ... How sad I am

  6. #6
    Join Date
    Dec 2008
    Location
    TaganrogNativelandChehov,Russia
    Posts
    64
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sending event from child widget

    east or west home is best

  7. #7
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sending event from child widget

    I dont understand what you mean

    I can't create any QGraphicsSceneMouseEvent since its constructor is private.
    And I read in the doc that the QMouseEvent in the QGraphicsView is translated to a QGraphicsSceneMouseEvent then sent to the QGraphicsScene and then to the QGraphicsItem.

    So, theorically, I only need to send event to the view.

Similar Threads

  1. let parent widget grow with child widget?
    By BeS in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2009, 11:17
  2. Custom event gets not propagated to the top level widget
    By nightghost in forum Qt Programming
    Replies: 0
    Last Post: 29th January 2009, 09:06
  3. Child Widget is hogging the MouseReleaseEvent
    By Cruz in forum Qt Programming
    Replies: 1
    Last Post: 24th January 2009, 18:28
  4. How to get focus event in child widget
    By YuriyRusinov in forum Qt Programming
    Replies: 4
    Last Post: 17th October 2006, 07:53
  5. qt network performance
    By criss in forum Qt Programming
    Replies: 16
    Last Post: 24th July 2006, 09:23

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.