MousePressEvent and MouseReleaseEvent not Working in QT5.8



  • 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.



  • @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.


  • Moderators

    @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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.