1 year ago

#211649

test-img

Martin Denion

How to prevent a QMainWindow from being moved with moveEvent?

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?

c++

qt

qmainwindow

0 Answers

Your Answer

Accepted video resources