如何使用 PyQt 根据屏幕分辨率调整主窗口的大小 [英] How can I resize the main window depending on screen resolution using PyQt
问题描述
我有一个包含三个框架的主窗口.顶部框架由页眉组成,底部框架由页脚组成.我使用 PyQt4
设计器设计它.当我在我的笔记本电脑上运行它时窗口看起来很好,屏幕分辨率为 1920*1080
.但是当我在 1600*900
等其他分辨率上检查相同的内容时,页脚被切断了.我想知道是否有办法在运行时根据屏幕分辨率调整窗口大小,以便显示所有三个帧.我试图在线检查是否有任何解决方案,但找不到任何解决方案.我尝试使用 window.setGeometry
和 window.setFixedSize
函数,但没有用.
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.
窗口代码为:
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_()
推荐答案
您可以使用
showFullScreen() 或只是 showMaximized()代码>
您可以通过以下方式获取屏幕几何图形:
and you can get screen geometry with:
这篇关于如何使用 PyQt 根据屏幕分辨率调整主窗口的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!