Reputation: 1046
I want my window to be always maximized. I try setting:
setWindowFlags(Qt::Window | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint);
(...)
showMaximized();
setMinimumSize(QSize(width(), height()));
setFixedSize(QSize(width(), height()));
So the window is opened maximized, but I can still click its title bar and drag it down. When doing so Windows (10) is resizing window from maximized state to normal.
How can I disable this behavior for my window?
Upvotes: 1
Views: 1859
Reputation: 104589
Use the MSWindowsFixedSizeDialogHint
flag.
setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Window | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint);
Upvotes: 0
Reputation: 4602
I think the concept of maximizing the window is less efficient to maintain a dragable window. Instead , set the window geometry to maximum screen dimensions, then you can drag as needed without the system resizing your window.
To do that you need an instance of QDesktopWidget
which provides geometry information of your screen, like the full stretch width/height. then just set your window size to be fixed with those information.
In your Mainwindow .cpp add following:
QDesktopWidget* myscreen = QApplication::desktop();
int width = myscreen->width();
int height = myscreen->height();
this->setFixedSize(width, height);
ui->setupUi(this);
... ...
Edit
The window can still be fully dogging, you can still use w.showMaximized();
and the window won't drop its size upon drag.
Upvotes: 1
Reputation: 104589
Since Windows is always going to respond to the user clicking and dragging the title bar, you could consider Qt::FramelessWindowHint
. Then draw your own faux title bar as rectangle on the top of the window with your own minimized and close buttons as needed. You'll also need to draw your own border rectangle.
Upvotes: 0