How to disable the window to enlarge the icon using PyQt4?

I would like to know how to disable the Maximize button of a window in pyqt4. I am currently using QWidget.setFixedSize (self, QSize) to prevent the user window from being resized, however the maximize button is still on and when clicked causes the application to move to the upper left corner of the screen. I basically want to reproduce the behavior of a Windows calculator application where the maximization icon is grayed out. Does anyone know how to achieve this with PyQt4?

+4
source share
3 answers

Did not work with him, but studies seem to indicate a mess with the window flags.

QWidget has a method called setWindowFlags .

Here is the document for the Qt.WindowFlags class.

Here is a link for all flags. Find Qt.WindowMaximizeButtonHint

In general, it seems that you need to find a way to enable the Qt.CustomizeWindowHint flag and disable the Qt.WindowMaximizeButtonHint flag. In any case, you probably want this in addition to setFixedSize , so that a good start.

Edit:

Sort of

 win.setWindowFlags(win.windowFlags() | QtCore.Qt.CustomizeWindowHint) win.setWindowFlags(win.windowFlags() & ~QtCore.Qt.WindowMaximizeButtonHint) 

Assuming your import is something like this

 from PyQt4 import QtCore 

This will enable the CustomizeWindowHint flag and disable the WindowMaximizeButtonHint flag, hopefully. Let me know if this works at all.

Edit:

As the OP discovered, the only call requirement was the following:

 win.setWindowFlags(QtCore.Qt.WindowMinimizeButtonHint) 
+8
source

This works great:

 MainWindow.setWindowFlags(QtCore.Qt.WindowCloseButtonHint | QtCore.Qt.WindowMinimizeButtonHint) 
+2
source

you can set the maximum size and minimum size with the same values ​​as the maximize disappear button

0
source

Source: https://habr.com/ru/post/1500373/


All Articles