Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Event Filter doesnt work as expected [Solved]
Forum Updated to NodeBB v4.3 + New Features

Event Filter doesnt work as expected [Solved]

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Coderx
    wrote on last edited by
    #1

    I tried to override the keypressevent for my lineEdit control using eventFiltering.
    but when i run my application it doesnt do anything! i even set a break point inside the eventFiltering method , but i never get there!!?
    This is my source codes :
    MainWindow.h
    @
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    protected:
    bool eventFilter( QObject* sender, QEvent* event);

    private:
    Ui::MainWindow *ui;
    };

    #endif // MAINWINDOW_H
    @

    MainWindow.cpp:

    @
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "QMessageBox"
    #include <QKeyEvent>
    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    }

    bool MainWindow::eventFilter(QObject *sender, QEvent event)
    {
    if (sender == ui->lineEdit)
    {
    if(event->type()== QEvent::KeyPress)
    {
    QKeyEvent * keyEvent = (QKeyEvent
    )(event);
    if( keyEvent->key() == Qt::Key_Control)
    {
    QMessageBox::information(this,"Salam","Test");
    return true;
    }else
    {
    return false;
    }
    }
    }
    return QWidget::eventFilter(sender,event);
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }
    @

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      You didn't install the eventFilter. Have a look at "this":http://qt-project.org/doc/qt-4.8/qobject.html#installEventFilter

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Coderx
        wrote on last edited by
        #3

        Thank you very much :)

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You're welcome !

          Don't forget to update the thread's title to solved, other forum users will know that a solution has been found :)

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Coderx
            wrote on last edited by
            #5

            done :)
            the subject is edited and solved is added :)

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved