Results 1 to 11 of 11

Thread: Widget that receives the mouseReleaseEvent

  1. #1
    Join Date
    Feb 2009
    Posts
    45
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default Widget that receives the mouseReleaseEvent

    Excuse the trivial nature of the question , but I wanted to know how to get the widget which received the mouse click event.

    - I have a tabWidget with a few tabs, and when moving from one tab to another, I want to save changes before going to the next tab.
    - Example: I am in Tab1 where I an editing a textField, when the user clicks on another tab, before going to this tab, I want to run a function to save the contents.

    I am implementing the click event as follows:

    Qt Code:
    1. void MyClass::mouseReleaseEvent ( QMouseEvent * event )
    2. {
    3. if (event->buttons() == Qt::LeftButton)
    4. {
    5. // Here I want to get the widget on which the mouse has been clicked
    6. }
    7.  
    8. }
    To copy to clipboard, switch view to plain text mode 

    Thanks in advance.

  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: Widget that receives the mouseReleaseEvent

    I would react to hideEvent() instead of this.
    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
    Feb 2009
    Posts
    45
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default Re: Widget that receives the mouseReleaseEvent

    Thanks wysota for the suggestion.

    Following is what I tried

    My dialog consists of a TabWidget (myTabWid)
    myTabWid has 5 tab's : Tab1, Tab2...Tab5

    1. Added a connect only for Tab2, as I am concerned only with this tab
    Qt Code:
    1. connect (Tab2, SIGNAL(hideEvent()), this, SLOT(verifyTab2());
    To copy to clipboard, switch view to plain text mode 

    2. The SLOT function was added in the header file
    3. In verifyTab2, I execute my required code.

    But I notice this 'verifyTab2()' is not called!! Am I missing something here?
    Kindly advise. Thanks.

  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: Widget that receives the mouseReleaseEvent

    hideEvent is not a signal but an event, see QWidget::hideEvent(). Reimplement it for every widget you place into tab widget that you want monitored for being hidden.
    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
    Feb 2009
    Posts
    45
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default Re: Widget that receives the mouseReleaseEvent

    Thanks once again Wyosta.

    1. How do I implement the HideEvent (or any event for that matter) for an individual widget?
    2. My class contains the dialog which inturn contains the tabs and all the individual widgets.
    3. I tried reimplementing it for my class, but it was called only when I closed the dialog, not when I switched from one tab to another

    Qt Code:
    1. void MyClass::hideEvent(QHideEvent * event )
    2. {
    3. if (Tab2 == myTabWid->currentWidget() )
    4. verifyTab2();
    5.  
    6. }
    To copy to clipboard, switch view to plain text mode 

  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: Widget that receives the mouseReleaseEvent

    As I said you need to implement it for every widget serving as content for a page of your tab widget. Alternatively you can install an event filter (see QObejct::installEventFilter()).
    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
    Feb 2009
    Posts
    45
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default Re: Widget that receives the mouseReleaseEvent

    I tried associating the 'installEventFilter' to the concerned widget.

    Qt Code:
    1. bool MyClass::eventFilter(QObject *obj, QEvent *event)
    2. {
    3. if (event->type() == QEvent::Hide)
    4. {
    5. if (obj == Tab2)
    6. verifyTab2();
    7.  
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

    But when the event is called, the state of the tabWidget is 'gray', i.e. it hasn't loaded the new tab as yet, and the current tab contents have been removed.
    I want to trap the event when it is still in the current tab (Where I want to display a message 'Do you want to save before moving to next tab').

    What do you suggest?
    Last edited by qtUser500; 15th July 2009 at 15:53.

  8. #8
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Widget that receives the mouseReleaseEvent

    if (event->type() == QEvent::Hide())
    remove the brackets

  9. #9
    Join Date
    Feb 2009
    Posts
    45
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default Re: Widget that receives the mouseReleaseEvent

    Thanks Mr. Death, I made that correction, but notice the behavior mentioned in my previous comment.

  10. #10
    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: Widget that receives the mouseReleaseEvent

    This won't work then. You have to react on mouse release, use QTabBar::tabAt() to find which tab was clicked and if it is different than the current one use QTabWidget::currentWidget() to get the current tab and do your stuff.
    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.


  11. #11
    Join Date
    Feb 2009
    Posts
    45
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default Re: Widget that receives the mouseReleaseEvent

    Thanks Wyosta.

Similar Threads

  1. Replies: 2
    Last Post: 21st June 2009, 06:04
  2. Stacked widget mouse propagation
    By bunjee in forum Qt Programming
    Replies: 3
    Last Post: 14th November 2008, 17:54
  3. pass mouse event information to another widget
    By Rooster in forum Qt Programming
    Replies: 5
    Last Post: 12th July 2008, 04:23
  4. Replies: 4
    Last Post: 3rd March 2008, 22:15
  5. Forwarding mouse events to another widget.
    By yogeshm02 in forum Qt Programming
    Replies: 8
    Last Post: 28th February 2006, 13:25

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.