sci-guy
sci-guy

Reputation: 2584

How can I maximize my main window and prevent resize in QT

I am trying to maximize my main qt window upon running and prevent the user from resizing it. I have tried

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow widget;
    widget.showMaximized();
    widget.show();
    return a.exec();
}

Which does maximize the window, along with

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    this->setWindowFlags(this->windowFlags() | Qt::MSWindowsFixedSizeDialogHint);
    ui->setupUi(this);
}

which does grey out the "restore down", "maximize" button located in the title bar in the middle of minimize and close window.

But I am still able to drag the title bar down to unsnap the maximized window and then readjust the size with the corner and edges.

How can I prevent the ability to unsnap the window and no strictly no resizing.

Thanks!

Upvotes: 6

Views: 9441

Answers (1)

mkocabas
mkocabas

Reputation: 733

If you want Window frame disappear and maximize-lose-restoredown buttons invisible, you can modify UI part of your code as:

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
   this->setWindowFlags(this->windowFlags() | Qt::MSWindowsFixedSizeDialogHint);
   ui->setupUi(this);
   this->setWindowFlags(Qt::FramelessWindowHint); //Makes the frame invisible
   this->setWindowState(Qt::WindowMaximized); //Maximizes the window
}

Upvotes: 5

Related Questions