Results 1 to 4 of 4

Thread: Assigning event filter for widgets inside groupbox

  1. #1
    Join Date
    Nov 2012
    Location
    Coimbatore
    Posts
    53
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Assigning event filter for widgets inside groupbox

    Hi All,
    I have used three push buttons inside a groupbox and when I assign eventFilter() for the pushbuttons it gets hidden in the output screen. groupbox has NoFocus policy and pushbuttons has StrongFocus policy.

    Qt Code:
    1. test1::test1(QWidget *parent) :
    2. QDialog(parent, Qt::FramelessWindowHint),
    3. ui(new Ui::test1)
    4. {
    5. ui->setupUi(this);
    6. ui->pushButton_1->installEventFilter(this);
    7. ui->pushButton_2->installEventFilter(this);
    8. ui->pushButton_3->installEventFilter(this);
    9. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. bool test1::eventFilter(QObject *o, QEvent *e)
    2. {
    3. if(e->type()==QEvent::KeyPress)
    4. {
    5. return QObject::eventFilter(o,e);
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by anda_skoa; 19th June 2014 at 14:06. Reason: changed [qtclass] to [code]

  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: Assigning event filter for widgets inside groupbox

    Pay atention to compiler warnings, it should warn you that there is no return value in function returning bool:
    Qt Code:
    1. bool test1::eventFilter(QObject *o, QEvent *e){
    2. if(e->type()==QEvent::KeyPress){
    3. return QObject::eventFilter(o,e);
    4. }
    5. // and if not keyPress then ... ?
    6. }
    To copy to clipboard, switch view to plain text mode 
    Result returned by such function is undefined. Probably you are filtering out the paint events for these widgets.
    To fix this, always return default base class eventFilter() when you don't want to filter the event out:
    Qt Code:
    1. bool test1::eventFilter(QObject *o, QEvent *e){
    2. if(e->type()==QEvent::KeyPress){
    3. // handle key press
    4. return true; // filter out this event
    5. }
    6. return QDialog::eventFilter(o,e); // or whatever is the base class for test1
    7. }
    To copy to clipboard, switch view to plain text mode 
    To avoid such errors in the future, add this flag to compiler flags:
    Qt Code:
    1. -Werror=return-type
    To copy to clipboard, switch view to plain text mode 
    or better
    Qt Code:
    1. -Wall -Werror
    To copy to clipboard, switch view to plain text mode 

  3. The following 2 users say thank you to stampede for this useful post:

    anda_skoa (19th June 2014), d_stranz (21st June 2014)

  4. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Assigning event filter for widgets inside groupbox

    Your event filter is not returning for all cases, so the show or paint events are likely filtered out before they reach the buttons.

    What is it that you want to achieve?

    Cheers,
    _

  5. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,233
    Thanks
    303
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Assigning event filter for widgets inside groupbox

    Pay attention to compiler warnings, it should warn you that there is no return value in function returning bool
    Interesting. Visual C++ will not let you get away with this - it's a compilation error, not a warning. All paths must return a valid value when the return type is not void.

Similar Threads

  1. Locating clicks without an event filter?
    By tescrin in forum Qt Programming
    Replies: 0
    Last Post: 30th August 2012, 17:16
  2. how to get the last groupbox changed event in my program?
    By saman_artorious in forum Qt Programming
    Replies: 19
    Last Post: 1st August 2012, 06:12
  3. Replies: 0
    Last Post: 16th July 2012, 09:56
  4. Event filter question
    By d_stranz in forum Qt Programming
    Replies: 7
    Last Post: 7th July 2011, 23:08
  5. Problems putting layouts inside groupbox
    By conexion2000 in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 10:01

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.