[SOLVED] mouseReleaseEvent in custom QMdiSubWindow deactivates possibility to close the SubWindow

  • Hello everyone!

    I am quite new in Qt programming. I use the mouseReleaseEvent to detect, if a QMdiSubWindow has moved in a QMdiArea. Therefore I use a custom QMdiSubWindow called CustomQMdiSubWindow. There I implement the mouseReleaseEvent. The problem (or bug?) is now, that if you implement the mouseReleaseEvent, it is not possible to close the custom QMdiSubWindow anymore, by clicking on the close button in the menu. In the following you find a short code example:

    @#include "mainwindow.h"
    #include "ui_mainwindow.h"

    #include <custommdisubwindow.h>

    MainWindow::MainWindow(QWidget *parent) :
    ui(new Ui::MainWindow)

    CustomMdiSubWindow* sub = new CustomMdiSubWindow(ui->mdiArea);


    delete ui;


    #include <QMdiSubWindow>

    class CustomMdiSubWindow : public QMdiSubWindow
    explicit CustomMdiSubWindow(QWidget *parent = 0);

    public slots:
    void closeEvent(QCloseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);


    @#include "custommdisubwindow.h"
    #include <QDebug>

    CustomMdiSubWindow::CustomMdiSubWindow(QWidget *parent) :

    void CustomMdiSubWindow::closeEvent(QCloseEvent *event) {
    qDebug() << "Window Closed Event!";

    void CustomMdiSubWindow::mouseReleaseEvent(QMouseEvent *event) {
    qDebug() << "Mouse Release Event!";

    Thank you in advance for your help!

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    It's not the mouseReleaseEvent that's the problem. You are also reimplementing the closeEvent function and do nothing in it. The function's "documentation":http://qt-project.org/doc/qt-5/qwidget.html#closeEvent explains what you should do at minimum when reimplementing it.

  • Hello SGaist :),

    the reimplementation of the closeEvent function is not the problem. Even if I do not reimplement this function I have the same problem with the closability of the window. I just reimplemented the function that I see if there is some close event (I thought maybe the window is just not closed although the close event function is called).

  • Lifetime Qt Champion

    Then you should at least call the base class implementation especially if you do nothing in that function.

  • I called the base class in the mouseReleaseEvent function and now I do not have that problem anymore! Thank you a lot for your help! :)

Log in to reply

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