I've a simple pyqt application in which I've some code for UI which is responsible for realtime speech-to-text in application everything works fine but when I try to maximize my application by clicking on maximize icon it get remove and window does not maximized here is output how it looks
This is my code.
class MainWindow(QtWidgets.QWidget):
def __init__(self, *args, **kwargs) -> None:
super(MainWindow, self).__init__(*args, **kwargs)
self.setWindowTitle("Speech To Text")
self.setWindowFlags(self.windowFlags() | Qt.WindowMaximizeButtonHint)
self.setWindowFlags(self.windowFlags() | Qt.WindowCloseButtonHint)
self.setWindowFlags(self.windowFlags() | Qt.WindowMinimizeButtonHint)
self.app_name = QtWidgets.QLabel("Speech To Text")
self.hbox = QtWidgets.QHBoxLayout()
self.someButton1 = QtWidgets.QPushButton("btn1")
self.someButton2 = QtWidgets.QPushButton("btn2")
self.hbox.addWidget(self.someButton1)
self.hbox.addWidget(self.someButton2)
self.grid = QtWidgets.QGridLayout()
self.vbox = QtWidgets.QVBoxLayout()
self.topBtn1 = QtWidgets.QPushButton("Top Button 1")
self.topBtn2 = QtWidgets.QPushButton("Top Button 2")
self.topLayout = QtWidgets.QVBoxLayout()
self.topLayout.addWidget(self.topBtn1)
self.topLayout.addWidget(self.topBtn2)
self.startButton = QtWidgets.QPushButton()
self.startLabel = QtWidgets.QLabel()
self.startLabel.setText("Tap To Record")
self.startLayout = QtWidgets.QVBoxLayout()
self.startLayout.addWidget(self.startButton, alignment=Qt.AlignCenter)
self.startLayout.addWidget(self.startLabel, alignment=Qt.AlignCenter)
self.startLayout.addStretch()
self.stopButton = QtWidgets.QPushButton()
self.stopLabel = QtWidgets.QLabel()
self.stopLabel.setText("Stop")
self.stopLayout = QtWidgets.QHBoxLayout()
self.stopLayout.addWidget(self.stopButton)
self.stopLayout.addWidget(self.stopLabel)
self.vbox.addLayout(self.topLayout)
self.vbox.addLayout(self.startLayout)
self.vbox.addLayout(self.stopLayout)
self.vbox.addWidget(self.app_name, alignment=Qt.AlignCenter, stretch=1)
self.editor = QtWidgets.QTextEdit()
self.grid.addLayout(self.hbox, 0, 2)
self.grid.addLayout(self.vbox, 1, 1)
self.grid.addWidget(self.editor, 1, 2)
self.setLayout(self.grid)
I've not provided full code, only main code, and also I'm using Ubuntu, and some methods on the MainWindow class update the UI on clicking buttons (it is just for extra information). What's the issue please let me know because on same system another simple application works perfectly.
I figured out that the problem was different on Windows and Linux due to differences in spacing. I had added too much margin to the QVBoxLayout()
elements, causing them to overflow the screen. After reducing the margins and setting window.showMaximized()
, it now takes up the full screen width and height, and it's working now.
Make sure to test the spacing on different operating systems, such as Windows, Linux, and MacOS. In my case, Windows took a 150-point margin to give me the correct result, but in Linux it overflowed, so I set it to 50-point and it fixed!