MousePressEvent and MouseReleaseEvent not Working in QT5.8

  • I'm have that header and method override implemented:


    #ifndef ZoneFORM_H
    #define ZoneFORM_H

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

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

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

    class ZoneForm : public QDialog

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

    bool event(QEvent *event) override;

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

    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;

    Method overrided:
    bool ZoneForm::event(QEvent event)
    if (event->type() == QEvent::MouseButtonRelease ||
    event->type() == QEvent::MouseButtonPress) {
    buttonSender = qobject_cast<QPushButton*>(sender());
    qInfo("Entry on event general!!!");
    if (buttonSender == closeButton) {
    if (!priorityValidate()) {
    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.

  • Qt Champions 2018

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