Is it there a way to set a QMainWindow to be non-resizible in Qt Designer? I am seeing lots of coding examples but I want to do as much UI customization in Qt Designer as I can. So far I can only get this by setting the minimum size and maximum size to be equal, but still there is the resize arrow in the corner of the window and a "maximize" button on the top of the window.
6 Answers
When you select the QMainWindow, the properties of the object does contain a field for sizePolicy, both horizontal and vertical, as mentioned by the answer of @jester and you can set those to fixed.
I have found that doesn't always work and was never sure why (perhaps to due to layouts), but as you've found out, if you set the minimumSize and maximumSize fields to the same value, it does what you want.
As for the resize arrow and maximize button, I have never been able to do that from Qt Creator (designer), so I would say it's not possible. However, just one line of code is all you should need in the constructor of your class: -
setWindowFlags(Qt::Window | Qt::CustomizeWindowHint);
By default, the window flags include Qt::WindowMaximizeButtonHint. By setting the above flags, you're stating that you want to customise the window to include the specified elements. This will also remove the minimise button, so if you want that too, you should add Qt::WindowMinimizeButtonHint

- 27,181
- 6
- 55
- 85
-
Yeah, the size policies dont make anything change in here...I wanted to put all the UI in one file to be more MVC...but I guess there is no way then...many thanks – Michel Feinstein Nov 05 '13 at 19:22
-
with your code I can either have the minimize and close enables, with a grayed out disabled maximize, or no buttons at all...I as looking for only minimize and close, is it possible? Also the resize arrow is not gone – Michel Feinstein Nov 12 '13 at 08:47
I am not using Qt Designer; I am just writing a subclass of QMainWindow made from scratch. The solution I found for having a non-resizable window is to call setFixedSize on the QMainWindow after you have set up all your widgets and layouts. If you have set things up well, then you don't have to pick a size manually; you can just get the size from sizeHint. The line of code I used inside my subclass of QMainWindow is:
setFixedSize(sizeHint());
I tested this in Qt 5.5 on Windows 8.1 and everything looks fine: the maximize button gets disabled but the other buttons are still there, and the cursor does not indicate the possibility of resizing when the user moves it to the border.

- 84,103
- 24
- 152
- 189
-
1This doesn't work for me. WIndow doesn't show up at all. However, this does: `setFixedSize(size())` – RedBox Feb 13 '23 at 09:55
use the setFixedSize
property for the QMainWindow. In designer, if I remember correctly, you can set the horizontal and vertical sizePolicy
to Fixed
.

- 3,491
- 19
- 30
-
As I said, I want to do it in Qt Designer (clicking and choosing in the menus and options), the solution you gave is a coding one. – Michel Feinstein Nov 05 '13 at 07:42
-
@mFeinstein I remember there is an option to set horizontalSIzePolicy and verticalSizePolicy – jester Nov 05 '13 at 08:15
-
this policies dont make any change, in the window behaviour, i keep chamgimg them and i dont see anything... – Michel Feinstein Nov 05 '13 at 19:20
Sadly there is no option to do that; in VS you may find an option in the editor, to remove the mouse trigger that resize the window; but for some reason, QT5 does not have one.
I tried to use sizePolicy
and set it as fixed for mainWindow; but this does nothing for both the horizontal and vertical policy.
To solve the problem, I did set my mainwindow minimum
and maximum
size as the same values; and when you run the application, the mouse cursor won't be enabled for resizing.
It is an ugly way to do something so simple, but this is the only way I found in QT designer, without use code.
I solved the problem of Qt5 which is displaying mouse arrow resize window even with window having fixed size, but in Python, but you can make modifications for C++.
MainWindow.setWindowFlags(QtCore.Qt.MSWindowsFixedSizeDialogHint)

- 21
- 3
-
Do not post the same answers in several posts, if you think they are the same question then mark it as a duplicate if you can. Publishing the same answer in several publications is considered noise. – eyllanesc May 14 '19 at 01:34
It's an old post but I want to help if someone need it. I found a way (not so beautiful) but it works directly from QTDesigner. You can lock the resize by writing the values of height and width also inside "MinimumSize" and "MaximumSize" property. Oviously also set "Fixed" on vertical and horizontal as told by other users. This will remove the button to enlarge the window.

- 21
- 1
- 6