0

I would just like to be able to prevent my QMainWindow from being moved. I saw that it was possible to reimplement the moveEvent function.

Here is what I tried:

mainwindow.cpp

void MainWindow::moveEvent(QMoveEvent *event)
{
    qDebug() << "move";
    event->ignore();
}

mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QMessageBox>
#include <QTemporaryFile>
#include <QMoveEvent>

class MainWindow : public QMainWindow
{
    Q_OBJECT
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private:
    void moveEvent(QMoveEvent *event);

};

#endif // MAINWINDOW_H

My "moveEvent" function is called correctly, but I can still move the window, where am I wrong?

Martin Denion
  • 352
  • 1
  • 3
  • 22
  • From the [documentation](https://doc.qt.io/qt-6/qwidget.html#moveEvent): `"When the widget receives this event, it is already at the new position"`. So simply ignoring the event won't prevent the move. – G.M. Feb 22 '22 at 15:38
  • Ok I also realized it in the meantime, but how do you think we can do to prevent it from being moved? – Martin Denion Feb 22 '22 at 15:42
  • 2
    If the `QMainWindow` is a top level window then its properties re. moving, maximizing etc. are probably down to the window manager being used. Can I ask you why you want to prevent it being moved? It almost sounds like an xy-problem. – G.M. Feb 22 '22 at 15:51

0 Answers0