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. [SOLVED] mouseReleaseEvent in custom QMdiSubWindow deactivates possibility to close the SubWindow
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.3k Views 1 Watching
  • 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.
  • K Offline
    K Offline
    kaffeebiel
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kaffeebiel
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kaffeebiel
            wrote on last edited by
            #5

            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! :)

            1 Reply Last reply
            0

            • Login

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