Results 1 to 14 of 14

Thread: Event filter with mouse events

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2011
    Posts
    19
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Event filter with mouse events

    Sorry for misleading.

    When i click Start Debugging (F5) debug stops at this
    The code from Compile Output:

    Running build steps for project Mysz...
    Configuration unchanged, skipping qmake step.
    Starting: "E:\Programy\QtSDK\mingw\bin\mingw32-make.exe"
    E:/Programy/QtSDK/mingw/bin/mingw32-make -f Makefile.Debug
    mingw32-make[1]: Entering directory `C:/Users/Lukasz/Desktop/Mysz-build-desktop'
    mingw32-make[1]: Nothing to be done for `first'.
    mingw32-make[1]: Leaving directory `C:/Users/Lukasz/Desktop/Mysz-build-desktop'
    The process "E:\Programy\QtSDK\mingw\bin\mingw32-make.exe" exited normally.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Event filter with mouse events

    please stop post external links with screenshots.
    Attach the screenshots to the post, since after some time the external links stop being valid, and the post loses information, which might be important for people reading this in later time.
    Also, for posting a section of code you can simple cope the code and paste it here with [code] tags.

    Where is 'pushButton' defined, and where do you initialize it?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jul 2011
    Posts
    19
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Event filter with mouse events

    It's a screenshot window.jpg.

    I didn't have a defined pushButton so i added it:
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6. QPushButton *pushButton = new QPushButton("button1",this);
    7. pushButton->installEventFilter(this);
    8. }
    To copy to clipboard, switch view to plain text mode 
    Now the program stops crashing.
    I'm wondering why the event filter don't working.
    Qt Code:
    1. bool MainWindow::eventFilter(QObject *object, QEvent *ev)
    2. {
    3. if ((object == pushButton) && ev->type() == QEvent::Enter)
    4. {
    5. QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
    6. return true;
    7. }
    8. if ((object == pushButton) && ev->type() == QEvent::Leave)
    9. {
    10. QApplication::restoreOverrideCursor();
    11. return true;
    12. }
    13. else
    14. return false;
    15. }
    To copy to clipboard, switch view to plain text mode 
    When the cursor is on button he should change a type to cross but he don't change.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Event filter with mouse events

    I didn't have a defined pushButton so i added it:
    Thats is not true.
    If there was not a defined 'pushButton' you would have gotten a compile error.
    Which is also the reason your event handler "is not working".
    You have a defined a local 'pushButton' in your constructor, which is being initialized, but the 'pushButton' in your evnetFilter is declared somewhere else, probably in your header in class scope, but it is not initialized, hence it never matcher your if() statements.
    It seems you have no idea how classes in C++ work, and what are members.
    Hence, this is becoming off topic for this forum.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Jul 2011
    Posts
    19
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Event filter with mouse events

    I solved my problem.
    .h
    Qt Code:
    1. ...
    2. QPushButton *pushButton;
    3. ....
    To copy to clipboard, switch view to plain text mode 
    and .cpp
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6. pushButton = new QPushButton("button1",this);
    7. pushButton->setGeometry(50,45,60,25);
    8. pushButton->installEventFilter(this);
    9. }
    To copy to clipboard, switch view to plain text mode 
    high_flyer anyway thanks for help.

Similar Threads

  1. Event filter question
    By d_stranz in forum Qt Programming
    Replies: 7
    Last Post: 7th July 2011, 23:08
  2. Find QObjects that insatlled event filter
    By babu198649 in forum Qt Programming
    Replies: 4
    Last Post: 15th December 2010, 11:27
  3. problem with event filter compile for S60
    By jimiq in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 6th July 2010, 19:48
  4. Event Filter & No Focus problem
    By AlexanderPopov in forum Newbie
    Replies: 0
    Last Post: 22nd December 2009, 20:15
  5. Q3Table event filter problem
    By batileon in forum Qt Programming
    Replies: 2
    Last Post: 27th August 2008, 10:40

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.