6

I have a main window with three frames.The top frame consists of the header and the bottom frame consists of the footer. I designed it using the PyQt4 designer.The window looks fine when I run it on my laptop with a screen resolution of 1920*1080. But when I check the same on other resolutions like 1600*900 the footer gets cut off. I wanted to know if there is a way to resize the window according to screen resolution in the runtime so that all the three frames are shown. I tried to check online if there are any solutions for this but could not find any. I tried using window.setGeometry and window.setFixedSize functions,but it did not work.

The code for the window is:

import sys
import os
import threading
import smtplib

from PyQt4 import QtCore, QtGui, uic
import sched
import time

form_class = uic.loadUiType("FirstTest.ui")[0]                 # Load the UI
try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    _fromUtf8 = lambda s: s

class MyWindowClass(QtGui.QMainWindow, form_class):
    def __init__(self, parent=None):
        QtGui.QMainWindow.__init__(self, parent)        
        self.setupUi(self)        

#has some code for the field values to be shown







app = QtGui.QApplication(sys.argv)
myWindow = MyWindowClass(None)
#myWindow.setFixedSize(500,500)
myWindow.showMaximized()
palette = QtGui.QPalette()
palette.setColor(QtGui.QPalette.Background,QtCore.Qt.white)
myWindow.setPalette(palette)
myWindow.show()
app.exec_()
Jablonski
  • 18,083
  • 2
  • 46
  • 47
Valla
  • 2,414
  • 11
  • 42
  • 73

1 Answers1

6

You can use

showFullScreen() or just showMaximized()

and you can get screen geometry with:

desktop() and screenGeometry()

Jablonski
  • 18,083
  • 2
  • 46
  • 47
  • When I use window.showFullScreen() it is takiing up the entire screen and the close button on the button also disappears and there is no way to close the window. Could you give me an example of how it can be used. – Valla Nov 24 '14 at 16:49
  • @Valla I understood, see my edit about showMaximized, I think it is what are you looking for. – Jablonski Nov 24 '14 at 16:55
  • Still does not work. I used QT4 designer to work on the panels.So should the widget and the frame width be resized through the designer itself? – Valla Nov 24 '14 at 17:23
  • @Valla so do you use layouts? Layout can resize all elements accordingly to size of main window. It can't be done in designer because designer with with your current screen. – Jablonski Nov 24 '14 at 17:29
  • I have edited my question and included the code that is there in my .py file. I did not use any layout in the designer while creating the form. – Valla Nov 24 '14 at 17:35
  • @Valla so without layout all resizing has no any sence, so use layout, see tutorials in web. For example: http://qt-project.org/doc/qt-4.8/designer-layouts.html – Jablonski Nov 24 '14 at 17:40
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/65621/discussion-between-valla-and-chernobyl). – Valla Nov 25 '14 at 16:22