[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:
mainwindow.cpp
@#include "mainwindow.h"
#include "ui_mainwindow.h"#include <custommdisubwindow.h>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);CustomMdiSubWindow* sub = new CustomMdiSubWindow(ui->mdiArea);
}
MainWindow::~MainWindow()
{
delete ui;
}@custommdisubwindow.h
@#ifndef CUSTOMMDISUBWINDOW_H
#define CUSTOMMDISUBWINDOW_H#include <QMdiSubWindow>
class CustomMdiSubWindow : public QMdiSubWindow
{
Q_OBJECT
public:
explicit CustomMdiSubWindow(QWidget *parent = 0);public slots:
void closeEvent(QCloseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
};#endif // CUSTOMMDISUBWINDOW_H@
custommdisubwindow.cpp
@#include "custommdisubwindow.h"
#include <QDebug>CustomMdiSubWindow::CustomMdiSubWindow(QWidget *parent) :
QMdiSubWindow(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!
-
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).
-
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! :)