Important: Please read the 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)
        this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);

  • 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