我如何在活动屏幕上居中窗口而不是在普通屏幕上?此代码将窗口移动到一般屏幕的中心,而不是活动屏幕:
import sys
from PyQt4 import QtGui
class MainWindow(QtGui.QWidget):
def __init__(self):
super(MainWindow, self).__init__()
self.initUI()
def initUI(self):
self.resize(640, 480)
self.setWindowTitle('Backlight management')
self.center()
self.show()
def center(self):
frameGm = self.frameGeometry()
centerPoint = QtGui.QDesktopWidget().availableGeometry().center()
frameGm.moveCenter(centerPoint)
self.move(frameGm.topLeft())
def main():
app = QtGui.QApplication(sys.argv)
mainWindow = MainWindow()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
Run Code Online (Sandbox Code Playgroud)
如果我移除self.center()从initUI()然后窗口上为0x0打开活性屏幕上.我需要在活动屏幕上打开窗口并将此窗口移动到此屏幕的中心.Thansk!
我有一个包含三个框架的主窗口。顶部框架包含页眉,底部框架包含页脚。我使用设计器进行PyQt4设计。当我在屏幕分辨率为的笔记本电脑上运行该窗口时,该窗口看起来不错1920*1080。但是,当我在其他分辨率上进行检查时,例如1600*900页脚被切断。我想知道是否有一种方法可以在运行时根据屏幕分辨率调整窗口大小,以便显示所有三个框架。我试图在线检查是否有任何解决方案,但找不到任何解决方案。我尝试使用window.setGeometry和window.setFixedSize函数,但是没有用。
该窗口的代码是:
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) …Run Code Online (Sandbox Code Playgroud) 具有功能
QApplication::desktop()->screenCount();
QApplication::desktop()->screenGeometry();
Run Code Online (Sandbox Code Playgroud)
我发现系统上有多少个屏幕以及它们位于哪个屏幕坐标上。现在,我想找出QWidget位于哪个屏幕上。我怎样才能做到这一点?我是否必须对照屏幕坐标检查QWidget的坐标,还是有一种更优雅的方法直接返回屏幕编号?
谢谢!