Results 1 to 7 of 7

Thread: using installEventFilter() on a QLable hides the image in the label.

  1. #1
    Join Date
    Jul 2011
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default using installEventFilter() on a QLable hides the image in the label.

    Hello All!!

    I am building a camera app using QT and openCV..... I need to create a mouse event on a QLabel inside a main window.... Sub Classing is not feasible for me.. so I went with using installEventFilter() ..... I checked and the mouse event is working fine but the image in the label is not visible.... can you tell me how to fix this problem??

    Thanks!!

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: using installEventFilter() on a QLable hides the image in the label.

    Whats wrong with subclassing ?
    It will be easier to help if you post eventFilter code.

  3. #3
    Join Date
    Jul 2011
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: using installEventFilter() on a QLable hides the image in the label.

    The problem with subclassing is that -- I have put the QLabel via the UI creator and then I have made a QLabel pointer in my code to point it to the ui element (for manual access). Now making a subclass of QLabel, I couldnt quite figure out how to point the derived class's pointer to the QLabel object in the UI. ( I tried using cast operators.. didnt work).

    My eventFilter() code has basically nothing... I'v just put a couple of qDebug messages with conditions. I'm quite sure there's nothing wrong with the eventFilter(). The only problem is .. by doing

    imageLabel->installEventFilter(this); (imageLabel is the name of the QLabel object)

    the image that was supposed to be in that Label is not visible.

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: using installEventFilter() on a QLable hides the image in the label.

    I'm quite sure there's nothing wrong with the eventFilter()
    Thats why I asked for implementation, if installing the event filter prevents the image from being displayed, then there obviously is something wrong with it What is the return value of your event filter ?
    I couldnt quite figure out how to point the derived class's pointer to the QLabel object in the UI
    Place QLabel on the form, right click on it and select "Promote to" option, then fill the class name and header file of your custom Label class.

  5. #5
    Join Date
    Jul 2011
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: using installEventFilter() on a QLable hides the image in the label.

    my eventFilter functuion is::

    bool MyAppName::eventFilter(QObject *obj, QEvent *event)
    {
    if (obj == imageLabel) {
    if (event->type() == QEvent::MouseButtonPress) {
    qDebug("Mouse has been pressed\n");

    }
    return true;
    } else {
    // pass the event on to the parent class
    return false;
    //return QMainWindow::eventFilter(obj, event);
    }
    }

    *The qDebug messange is being displayed when I click on the label.


    But thanks for the second tip about the sub class.. I'll try that and see what happens.

    Really appreciate your help. Thanks*A Million!

  6. #6
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: using installEventFilter() on a QLable hides the image in the label.

    Look, after proper code formatting the problem is obvious:
    Qt Code:
    1. bool MyAppName::eventFilter(QObject *obj, QEvent *event)
    2. {
    3. if (obj == imageLabel) {
    4. if (event->type() == QEvent::MouseButtonPress) {
    5. qDebug("Mouse has been pressed\n");
    6. // return true here, because ...
    7. }
    8. return true; // ... this will filter out ALL events for label ! including paint events;)
    9. } else {
    10. // pass the event on to the parent class
    11. return false;
    12. //return QMainWindow::eventFilter(obj, event);
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Jul 2011
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: using installEventFilter() on a QLable hides the image in the label.

    Gee... Thanks!! It worked perfectly!! I feel embarassed now!! Such a stupid mistake....

Similar Threads

  1. HOW TO DISPLAY A RECTANGLE ON AN IMAGE on a label
    By qt_user in forum Qt Programming
    Replies: 4
    Last Post: 6th August 2010, 15:19
  2. Replies: 5
    Last Post: 16th December 2009, 11:33
  3. Replies: 1
    Last Post: 1st June 2009, 20:58
  4. Replies: 1
    Last Post: 23rd May 2009, 09:04
  5. label with image and text
    By mattia in forum Newbie
    Replies: 1
    Last Post: 7th March 2008, 11:28

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.