How to make a window that occupies the full screen without maximising?
pyqt, pyside, python, qt
Solution
Use `QtGui.QApplication().desktop().availableGeometry()` for the size of the window:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
from PyQt4 import QtGui, QtCore
class MyWindow(QtGui.QWidget):
def __init__(self, parent=None):
super(MyWindow, self).__init__(parent)
self.pushButtonClose = QtGui.QPushButton(self)
self.pushButtonClose.setText("Close")
self.pushButtonClose.clicked.connect(self.on_pushButtonClose_clicked)
self.layoutVertical = QtGui.QVBoxLayout(self)
self.layoutVertical.addWidget(self.pushButtonClose)
titleBarHeight = self.style().pixelMetric(
QtGui.QStyle.PM_TitleBarHeight,
QtGui.QStyleOptionTitleBar(),
self
)
geometry = app.desktop().availableGeometry()
geometry.setHeight(geometry.height() - (titleBarHeight*2))
self.setGeometry(geometry)
@QtCore.pyqtSlot()
def on_pushButtonClose_clicked(self):
QtGui.QApplication.instance().quit()
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
app.setApplicationName('MyWindow')
main = MyWindow()
main.show()
sys.exit(app.exec_())
Problem
I'm writing in python using Qt I want to create the application window (with decorations) to occupy the full screen size. Currently this is the code I have: ``` avGeom = QtGui.QDesktopWidget().availableGeometry() self.setGeometry(avGeom) ``` the problem is that it ignores window decorations so the frame is larger... I googled and what not, found this: http://harmattan-dev.nokia.com/docs/library/html/qt4/application-windows.html#window-geometry which seems to indicate I need to set the frameGeometry to the `avGeom` however I haven't found a way to do that. Also, in the comments in the above link it says what I'm after may not be even possible as the programme can't set the frameGeometry before running... If that is the case I just want confirmation that my problem is not solvable. EDIT: So I played around with the code a bit and this gives what I want... however the number 24 is basically through trial and error until the window title is visible.... I want some better way to do this... which is window manager independent.. ``` avGeom = QtGui.QDesktopWidget().availableGeometry() avGeom.setTop(24) self.setGeometry(avGeom) ``` Now I can do what I want but purely out of trial and error Running Ubuntu, using Spyder as an IDE thanks