7

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

evan54
  • 3,585
  • 5
  • 34
  • 61
  • According to me this is the answer! http://stackoverflow.com/questions/6541771/fullscreen-with-pyqt4 – karelv Aug 26 '16 at 19:14

2 Answers2

11

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_())
  • no this didn't work... what happened now was that the widget was the size of the entire screen as opposed to it being the entire screen minus the menu bar (start-type button always on the screen)... Ideally I want everything minus menu bar minus space required for title (aka decorations) – evan54 Mar 29 '13 at 14:23
  • @evan54 Checkout my [updated answer](http://stackoverflow.com/a/15703882/1006989), I modified it to hide the title bar (Notice the use of `availbleGeometry` instead of `screenGeometry`). –  Mar 29 '13 at 15:40
  • eee still not what I want... I don't really want to hide the title bar I just want the geometry I set account for the fact there is a title bar... sorry if I'm confusing you – evan54 Mar 29 '13 at 16:32
  • @evan54 Does my answer without the `setWindowFlags` part resolve your issue? –  Mar 29 '13 at 16:50
  • no... the problem I get is that it will make the widget size to be correct, however, the window = widget + title are bigger than the screen... If you look at the link I've posted Ι think you'll understand what I mean – evan54 Mar 29 '13 at 16:55
  • added some sort of way that it works, it may make the question more understandable – evan54 Mar 29 '13 at 17:02
  • See if my [latest update](http://stackoverflow.com/a/15703882/1006989) is working for you –  Mar 29 '13 at 17:05
  • yes what kind of magic was that! I'm trying to understand what your code does... Why not just use `QtGui.QStyle.PM_TitleBarHeight` ? – evan54 Mar 29 '13 at 17:16
  • although I slightly modified what you did, I used `avGeom.setTop(titlebarheight)` – evan54 Mar 29 '13 at 17:19
  • Ok! ;) The size of the titlebar will be different depending on the style of the widget, that's why you shouldn't use it directly. Once you have the size of the titlebar you subtract it to the height value of the geometry, if `setTop` work for you, go with it! :) –  Mar 29 '13 at 17:24
4

I've always found inheritting from the QMainWindow class to be particularly useful. Like this:

import sys
from PySide.QtGui import *
from PySide.QtCore import *


class Some_APP(QMainWindow):

    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        ### this line here is what you'd be looking for
        self.setWindowState(Qt.WindowMaximized)
        ###
        self.show()


def main():
    app = QApplication(sys.argv)
    some_app = Some_APP()
    sys.exit(app.exec_())


if __name__ == "__main__":
    main()
LastTigerEyes
  • 647
  • 1
  • 9
  • 21