#include #include #include #include #include #include class customWidget : public QWidget { public: customWidget() : QWidget(nullptr) {} ~customWidget() override {} protected: void mousePressEvent(QMouseEvent* event) override { if (event->button() == Qt::LeftButton && rect().contains(event->pos())) { windowHandle()->startSystemMove(); event->accept(); } else { return QWidget::mousePressEvent(event); } } }; class customWidget2 : public QWidget { public: customWidget2() : QWidget(nullptr) { //this can changed to Qt::FramelessWindowHint setWindowFlags(Qt::CustomizeWindowHint); // QHBoxLayout asdfdd; setLayout(&asdfdd); QPushButton* asdf {new QPushButton}; asdf->setText("where is window animation?"); asdfdd.addWidget(asdf); QObject::connect(asdf, &QPushButton::clicked, [this] () { Qt::WindowStates Local_WindowState {windowState()}; if (Local_WindowState & Qt::WindowMaximized) { showNormal(); } else if (Local_WindowState == Qt::WindowMinimized || Local_WindowState == Qt::WindowNoState) { showMaximized(); } }); } ~customWidget2() override {} protected: void mousePressEvent(QMouseEvent* event) override { if (event->button() == Qt::LeftButton && rect().contains(event->pos())) { windowHandle()->startSystemMove(); event->accept(); } else { return QWidget::mousePressEvent(event); } } private: bool m_Maximized {false}; }; int main(int argc, char *argv[]) { QApplication a(argc, argv); //1 customWidget w; w.resize(800, 600); QHBoxLayout asdfdd; w.setLayout(&asdfdd); QPushButton* asdf {new QPushButton}; asdf->setText("asdfffwqq"); asdfdd.addWidget(asdf); w.show(); //2 customWidget2 w2; w2.resize(400, 300); w2.show(); return a.exec(); }