Results 1 to 4 of 4

Thread: undermouse() function not working

  1. #1
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Question undermouse() function not working

    hi
    i have a Qstackedwidget in which Qlistview and Qlabel are added . i have subclassed the main class which contains Qstackedwidget to receive mousepress events

    inside the mousepress event i have if statement like this

    QStackedWidget *stackedwidget;
    if(stackedwidget->underMouse())
    cout<<"hi";

    when the label is under mouse it works fine ,but when Qlistview is under mouse it doesnot detect. is it possible to make it right.

    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: undermouse() function not working

    Retrieve the event position from the event object and then test whether the rect() of the class contains the position of the event, like so:
    Qt Code:
    1. void someClass::mousePressEvent(QMouseEvent *me){
    2. QPoint pos = me->pos();
    3. if(stackedwidget->rect().contains(pos)){
    4. qDebug("STACK WIDGET HERE");
    5. }
    6. }
    To copy to clipboard, switch view to plain text mode 

    Note that this will not work if the child widget you want to test against handles the mouse press event itself (like QListView probably does). In that situation you have to reimplement the event in the widget in question or apply an event filter on the child widget to monitor its events. See the docs for reference on event filters.

  3. #3
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Smile Re: undermouse() function not working

    thank u wysota
    is there any way to stop all the widgets in the main window receiving events
    and all the events should be send by mainwindow.
    i know event filter may do this but main window must require knowledge of its child widgets, is it possible to stop the events of the childs without the knowldege of the number of childs the main window has.

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: undermouse() function not working

    AFAIK you can get *all* events by installing the eventfilter on qApp. This way you could get all events from all widgets. Be sure to pass on the events you are not interested in.

Similar Threads

  1. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  2. Link Errors
    By magikalpnoi in forum Qt Programming
    Replies: 5
    Last Post: 25th September 2006, 22:04
  3. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52
  4. Qt 4.1.4 plugin QPSQL
    By jcr in forum Installation and Deployment
    Replies: 4
    Last Post: 22nd June 2006, 22:55
  5. I got two problems when I used static compiled library of QT4
    By qintm in forum Installation and Deployment
    Replies: 8
    Last Post: 20th April 2006, 08:52

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.