Results 1 to 6 of 6

Thread: MousePressEvent on Widget stops event propagation

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2011
    Posts
    42
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question MousePressEvent on Widget stops event propagation

    Hi,
    I have built a custom combo box, its basically a Widget with 2 buttons. Clicking on any of them displays another widget below them, showing the combo.
    This combo displays the items with a Tree View, This is used to display an AddressBar, where the main/root items are the names of the contacts and the subitems (childs) are the several emails of each person.

    The thing is that in order to simulate the QComboBox behaviour, the combo must disappear when the user clicks outside or when clicking on the buttons again.

    For the combo i have used a Widget as a wrapper for the TreeView, applying the Qt::Popup flag. That didnt help. Popup widgets by default get hidden when clicking outside, but in the case i click on the button, the combo was hidden and as a result of clicking outside of the view, then the click was detected on the button and the view was shown again, since it was not visible. I couldnt hide the view when clicking back on the button.

    What i found out is that: when the QWidget is visible, it get the mouse press event. Checks if the event position is inside it, and if so, hides it. When the widget is hidden, then the click event is detected on the button.
    So i overrided the implementation of MousePressEvent in the QWidget that wrapps the QTreeView to play a little, copying exactly what QWidget does, and i found that if i DONT hide the QWidget on the mousePressEvent, then the click is NOT detected on the button.

    Is it possible that the MousePressEvent is not propagating the event when the QWidget is visible? The QWidget has no parent at all, but when hidden by the mouse click, the event is informed to the button.

    Any ideas?
    Thanks

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

    Default Re: MousePressEvent on Widget stops event propagation

    The second half of your post is somewhat unclear (to many "it" in one sentence, I guess...). You want the event to be propagated or not? And in what conditions? If you override some event handler and don't call ignore() then the event is accepted and no propagation occurs. I don't know if that answers your question...
    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.


  3. #3
    Join Date
    Jul 2011
    Posts
    42
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MousePressEvent on Widget stops event propagation

    mmm yeah i had a hard time trying to make it clear.

    The thing is: if i click on the button, i want the QWidget that handles the view, NOT to be hidden because of an outside click, and handle the click event on the button.
    i tried several combinations of ignore, accept. I also tried verifying the position of the click, and only hiding the QWidget if the position didnt include the view nor the button. In that case the view wasnt hidden, but the button never got the click event.

    Somehow when the QWidget that is catching the mouse events on the MousePressEvent, is not hidden, the event doesnt propagate. It only escalates if i hide the widget.

    Is it clearer now?
    Thanks!

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

    Default Re: MousePressEvent on Widget stops event propagation

    I'm still not clear what the problem is. Qt::Popup works in such a way that the widget gets hidden regardless where you click if you click outside the widget area and I don't think there is anything you can do about it. The event won't propagate anywhere because the popup widget doesn't have a parent. The only thing you can do is to install the event filter on the popup, detect that the click happens outside the widget area and at that moment post another event to the widget under the cursor, letting the original event close the popup.
    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. Event propagation-Windows key special case
    By hanumanth in forum Qt Programming
    Replies: 0
    Last Post: 16th April 2010, 15:46
  2. Event propagation direction
    By spraff in forum Qt Programming
    Replies: 0
    Last Post: 6th December 2008, 21:03
  3. Graphics View Event Propagation
    By pherthyl in forum Qt Programming
    Replies: 10
    Last Post: 3rd July 2008, 10:39
  4. Replies: 1
    Last Post: 16th October 2007, 22:41
  5. How to prevent Event Propagation to Parent?
    By viking in forum Qt Programming
    Replies: 6
    Last Post: 9th May 2007, 06:29

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
  •  
Qt is a trademark of The Qt Company.