zoukankan      html  css  js  c++  java
  • [PyQt]PyQt5获取显示屏信息以及双屏显示实现

    一、使用QDesktopWidget类实现

    1. QDesktopWidget的实例通过QApplication类的静态方法desktop()获取。

    desktop = QApplication.desktop()

    2. 使用desktop的screenCount()方法获取显示器数量。

    screen_count = desktop.screenCount()

    3. 使用desktop的screenGeometry()方法获取显示屏的几何位置和尺寸;使用desktop的availableGeometry()获取可用位置和尺寸(除去任务栏等)。

    screen_rect = desktop.screenGeometry(0)          #参数为显示屏索引,如果安装了两个显示屏,主显示屏索引为0,辅显示屏索引为1

    available_rect = desktop.availableGeometry(0)          #参数为显示屏索引,如果安装了两个显示屏,主显示屏索引为0,辅显示屏索引为1

    4. 使用QWidget或QDialog类的setGeometry()方法就可以实现任一显示屏显示。

    widget = QWidget()

    widget.setGeometry(desktop.screenGeometry(0)        #在主屏显示(全屏)。如果不打算全屏显示,只需将widget的geometry设置在desktop的geometry内就可以了。

    dialog = QDialog()

    dialog.setGeometry(desktop.screenGeometry(1)        #在辅屏显示(全屏)。如果不打算全屏显示,只需将widget的geometry设置在desktop的geometry内就可以了。

    二、使用QApplication类实现

    1. 获取主显示屏对象(QScreen对象)。

    primary_screen = QApplication.primaryScreen()

    2. 获取所有显示屏对象(QScreen对象列表)。在双显示屏的情况下,除主显示屏以外的那个显示屏就是辅显示屏了。

    screens = QApplication.screens()

    for screen in screens:

      if not screen is primary_screen:

        auxiliary_screen = screen

        break

    else:

      auxiliary_screen = None

    3. 使用QScreen对象的geometry()方法和availableGeometry()方法获取几何位置尺寸以及可用位置尺寸。例如:

    primary_rect = primary_screen.geometry()

    primary_available_rect = primary_screen.availableGeometry()

    4. 使用QWidget或QDialog类的setGeometry()方法就可以实现任一显示屏显示。

    widget = QWidget()

    widget.setGeometry(primary_screen.geometry()        #在主屏显示(全屏,不显示任务栏)。如果不打算全屏显示,只需将widget的geometry设置在screen的geometry内就可以了。

    dialog = QDialog()

    dialog.setGeometry(auxiliary_screen.availableGeometry()        #在辅屏显示(全屏,显示任务栏)。如果不打算全屏显示,只需将widget的geometry设置在screen的geometry内就可以了。

  • 相关阅读:
    【ARM】2440裸机系列-RTC数字时钟
    【ARM】2440裸机系列-图片显示
    【Acm】算法之美—Anagrams by Stack
    【C/C++】程序如何来,编译全过程
    【Cmd】批处理
    【Cmd】那些年,我们迷恋的cmd命令(二)
    【Cmd】那些年,我们迷恋的cmd命令(一)
    【web技术】html特效代码(二)
    【web技术】html特效代码(一)
    【安全】加密解密整理
  • 原文地址:https://www.cnblogs.com/syh6324/p/9502307.html
Copyright © 2011-2022 走看看