小编App*_*ohn的帖子

PyQt4活动屏幕上的中心窗口

我如何在活动屏幕上居中窗口而不是在普通屏幕上?此代码将窗口移动到一般屏幕的中心,而不是活动屏幕:

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!

python user-interface pyqt pyqt4 python-3.x

14
推荐指数
2
解决办法
1万
查看次数

标签 统计

pyqt ×1

pyqt4 ×1

python ×1

python-3.x ×1

user-interface ×1