Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Still can resize the Window after setSizePolicy to fixed



  • Hi, here's the constructor of my MainWindow class. I set the window size policy to fixed, and updateGeometry, but still can resize the window. Why it can't work? Maybe I used it in a wrong way?

    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
        this->updateGeometry();
    }
    


  • Size policy is a layout attribute. So it only takes effect in layouts.
    It will never have any effect on a window.
    If you don't want your window to be resized, you should use setFixedSize.



  • @Bonnie Thank you ~


Log in to reply