Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I resize the main window depending on screen resolution using PyQt

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_()
like image 269
Valla Avatar asked Nov 24 '14 16:11

Valla


People also ask

How do I make my Pyqt5 window not resizable?

By using setFizedSize() method we can prevent the resizing of the image. Argument : It takes two integer as argument i.e width and height. Action performed : It set the fixed size of window.


1 Answers

You can use

showFullScreen() or just showMaximized()

and you can get screen geometry with:

desktop() and screenGeometry()

like image 113
Kosovan Avatar answered Oct 13 '22 11:10

Kosovan