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. MousePressEvent and MouseReleaseEvent not Working in QT5.8
Forum Update on Monday, May 27th 2025

MousePressEvent and MouseReleaseEvent not Working in QT5.8

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 2.1k Views
  • 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.
  • H Offline
    H Offline
    Henson
    wrote on last edited by
    #1

    I'm have that header and method override implemented:

    Header:

    #ifndef ZoneFORM_H
    #define ZoneFORM_H

    #include <QDialog>
    #include <QMouseEvent>
    #include <QEvent>

    QT_BEGIN_NAMESPACE
    class QDataWidgetMapper;
    class QDialogButtonBox;
    class QComboBox;
    class QLabel;
    class QLineEdit;
    class QPushButton;
    class QSqlRelationalTableModel;
    QT_END_NAMESPACE

    enum {
    Zone_Id = 0,
    Zone_MinVol = 1,
    Zone_MaxVol = 2,
    Zone_Priority = 3,
    Zone_ReservId = 4
    };

    class ZoneForm : public QDialog
    {
    Q_OBJECT

    public:
    ZoneForm(double mlimit, double maxrepvol, int reservid, int zoneid, QWidget *parent = 0);
    void done(int result);

    protected:
    bool event(QEvent *event) override;

    private slots:
    void addZone();
    void deleteZone();
    void maxLimitValidate();
    bool priorityValidate();

    private:
    QSqlRelationalTableModel *tableModel;
    QDataWidgetMapper *mapper;
    QLabel *minLimitLabel;
    QLabel *maxLimitLabel;
    QLabel *priorityLabel;
    QLabel *repositoryLabel;
    QComboBox *repositoryComboBox;
    QLineEdit *minLimitEdit;
    QLineEdit *maxLimitEdit;
    QLineEdit *priorityEdit;
    QPushButton *addButton;
    QPushButton *deleteButton;
    QPushButton *closeButton;
    QDialogButtonBox *buttonBox;
    double maxRepVol;
    double mlimit;
    double reservId;
    double zoneId;
    bool insertionMode;
    };
    #endif

    Method overrided:
    bool ZoneForm::event(QEvent event)
    {
    if (event->type() == QEvent::MouseButtonRelease ||
    event->type() == QEvent::MouseButtonPress) {
    QPushButton
    buttonSender = qobject_cast<QPushButton*>(sender());
    qInfo("Entry on event general!!!");
    if (buttonSender == closeButton) {
    if (!priorityValidate()) {
    event->ignore();
    return false;
    }
    }
    }
    return QWidget::event(event);
    }

    I have attempted use directly mousePressEvent and mouseReleaseEvent but nothing here.
    I'm working in projects on Ubuntu 16.04.
    Any help is a plus for me. Thank you.

    FlotisableF jsulmJ 2 Replies Last reply
    0
    • H Henson

      I'm have that header and method override implemented:

      Header:

      #ifndef ZoneFORM_H
      #define ZoneFORM_H

      #include <QDialog>
      #include <QMouseEvent>
      #include <QEvent>

      QT_BEGIN_NAMESPACE
      class QDataWidgetMapper;
      class QDialogButtonBox;
      class QComboBox;
      class QLabel;
      class QLineEdit;
      class QPushButton;
      class QSqlRelationalTableModel;
      QT_END_NAMESPACE

      enum {
      Zone_Id = 0,
      Zone_MinVol = 1,
      Zone_MaxVol = 2,
      Zone_Priority = 3,
      Zone_ReservId = 4
      };

      class ZoneForm : public QDialog
      {
      Q_OBJECT

      public:
      ZoneForm(double mlimit, double maxrepvol, int reservid, int zoneid, QWidget *parent = 0);
      void done(int result);

      protected:
      bool event(QEvent *event) override;

      private slots:
      void addZone();
      void deleteZone();
      void maxLimitValidate();
      bool priorityValidate();

      private:
      QSqlRelationalTableModel *tableModel;
      QDataWidgetMapper *mapper;
      QLabel *minLimitLabel;
      QLabel *maxLimitLabel;
      QLabel *priorityLabel;
      QLabel *repositoryLabel;
      QComboBox *repositoryComboBox;
      QLineEdit *minLimitEdit;
      QLineEdit *maxLimitEdit;
      QLineEdit *priorityEdit;
      QPushButton *addButton;
      QPushButton *deleteButton;
      QPushButton *closeButton;
      QDialogButtonBox *buttonBox;
      double maxRepVol;
      double mlimit;
      double reservId;
      double zoneId;
      bool insertionMode;
      };
      #endif

      Method overrided:
      bool ZoneForm::event(QEvent event)
      {
      if (event->type() == QEvent::MouseButtonRelease ||
      event->type() == QEvent::MouseButtonPress) {
      QPushButton
      buttonSender = qobject_cast<QPushButton*>(sender());
      qInfo("Entry on event general!!!");
      if (buttonSender == closeButton) {
      if (!priorityValidate()) {
      event->ignore();
      return false;
      }
      }
      }
      return QWidget::event(event);
      }

      I have attempted use directly mousePressEvent and mouseReleaseEvent but nothing here.
      I'm working in projects on Ubuntu 16.04.
      Any help is a plus for me. Thank you.

      FlotisableF Offline
      FlotisableF Offline
      Flotisable
      wrote on last edited by
      #2

      @Henson
      do you mean that the program does not enter the if statement in ZoneForm::event()?

      and I this you use the sender() in a wrong way.
      from the document, it is 0 if not called by a slot that is activated by a signal, and event() is not a slot.

      1 Reply Last reply
      2
      • H Henson

        I'm have that header and method override implemented:

        Header:

        #ifndef ZoneFORM_H
        #define ZoneFORM_H

        #include <QDialog>
        #include <QMouseEvent>
        #include <QEvent>

        QT_BEGIN_NAMESPACE
        class QDataWidgetMapper;
        class QDialogButtonBox;
        class QComboBox;
        class QLabel;
        class QLineEdit;
        class QPushButton;
        class QSqlRelationalTableModel;
        QT_END_NAMESPACE

        enum {
        Zone_Id = 0,
        Zone_MinVol = 1,
        Zone_MaxVol = 2,
        Zone_Priority = 3,
        Zone_ReservId = 4
        };

        class ZoneForm : public QDialog
        {
        Q_OBJECT

        public:
        ZoneForm(double mlimit, double maxrepvol, int reservid, int zoneid, QWidget *parent = 0);
        void done(int result);

        protected:
        bool event(QEvent *event) override;

        private slots:
        void addZone();
        void deleteZone();
        void maxLimitValidate();
        bool priorityValidate();

        private:
        QSqlRelationalTableModel *tableModel;
        QDataWidgetMapper *mapper;
        QLabel *minLimitLabel;
        QLabel *maxLimitLabel;
        QLabel *priorityLabel;
        QLabel *repositoryLabel;
        QComboBox *repositoryComboBox;
        QLineEdit *minLimitEdit;
        QLineEdit *maxLimitEdit;
        QLineEdit *priorityEdit;
        QPushButton *addButton;
        QPushButton *deleteButton;
        QPushButton *closeButton;
        QDialogButtonBox *buttonBox;
        double maxRepVol;
        double mlimit;
        double reservId;
        double zoneId;
        bool insertionMode;
        };
        #endif

        Method overrided:
        bool ZoneForm::event(QEvent event)
        {
        if (event->type() == QEvent::MouseButtonRelease ||
        event->type() == QEvent::MouseButtonPress) {
        QPushButton
        buttonSender = qobject_cast<QPushButton*>(sender());
        qInfo("Entry on event general!!!");
        if (buttonSender == closeButton) {
        if (!priorityValidate()) {
        event->ignore();
        return false;
        }
        }
        }
        return QWidget::event(event);
        }

        I have attempted use directly mousePressEvent and mouseReleaseEvent but nothing here.
        I'm working in projects on Ubuntu 16.04.
        Any help is a plus for me. Thank you.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by jsulm
        #3

        @Henson To add to @Flotisable : why do you implement event handler if you're only interested in mouse press/release on your push buttons? QPushButton has pressed() and released() signals - just use those.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1

        • Login

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