zoukankan      html  css  js  c++  java
  • 在qt下获取屏幕分辨率

    1,在Windows下可以使用 GetSystemMetrics(SM_CXSCREEN);GetSystemMetrics(SM_CYSCREEN) 获取。   2,在Linux下可以使用XDisplayWidth ;XDisplayHeight ()获取。
    3,在QT中呢?很多人说是 QApplication::desktop()->width();QApplication::desktop()->height(); 这个方法对于单显示器模式当然没有问题。但是对于多显示器,特别是使用了扩展桌面的就会有问题了。今天上午仔细看了QDesktopWidget的帮助,需要使用QApplication::desktop()->screenGeometry();这个函数有好几个重载的版本,意思都一样。该函数返回一个QRect,这个QRect的宽和高就是所在Screen的分辨率。获取方法如下:

    void GetScreenInfo()
    {
        QDesktopWidget* desktopWidget = QApplication::desktop();
        //获取可用桌面大小
        QRect deskRect = desktopWidget->availableGeometry();
        //获取设备屏幕大小
        QRect screenRect = desktopWidget->screenGeometry();

        g_nActScreenX = screenRect.width();
        g_nActScreenY = screenRect.height();
        //g_nActScreenX = deskRect.width();
        //g_nActScreenY = deskRect.height();

        //获取系统设置的屏幕个数(屏幕拷贝方式该值为1)
        g_nScreenCount = desktopWidget->screenCount();
    }说到这里,顺便标记以下多屏幕设置成拷贝方式时,获取的屏幕的个数是一个,只有设置成扩展时才返回多个。

    打印屏幕分辨率和个数信息:

    void printscreeninfo()

    {
        QDesktopWidget *dwsktopwidget = QApplication::desktop();
        QRect deskrect = dwsktopwidget->availableGeometry();
        QRect screenrect = dwsktopwidget->screenGeometry();
        QDesktopWidget *dwsktopwidget = QApplication::desktop();
        QRect deskrect = dwsktopwidget->availableGeometry();
        QRect screenrect = dwsktopwidget->screenGeometry();
        int scrcount = dwsktopwidget->screenCount();
        qCritical("screenrect.w==%s ",qPrintable(QString::number(screenrect.width())));
        qCritical("screenrect.h==%s ",qPrintable(QString::number(screenrect.height())));
        qCritical("deskrect.w==%s ",qPrintable(QString::number(deskrect.width())));
        qCritical("deskrect.h==%s ",qPrintable(QString::number(deskrect.height())));
        qCritical("scrcount==%s ",qPrintable(QString::number(scrcount)));

    }

    http://blog.csdn.net/ftworld21/article/details/15025797

  • 相关阅读:
    VMware Workstation Pro 12 创建虚拟机(安装Ubuntu)
    老师的题目(开心一刻)
    政务私有云盘系统建设的工具 – Mobox私有云盘
    学校信息化分享-中小学怎样快速完成教学资源库的建设
    SpringBoot 2.x 文件上传出现 The field file exceeds its maximum permitted size of 1048576 bytes
    nginx错误集
    nginx做http强制跳转https,接口的POST请求变成GET
    swagger Base URL地址和下边的不一致
    CentOS7关闭防火墙
    nginx配置:静态访问txt文件
  • 原文地址:https://www.cnblogs.com/findumars/p/5578771.html
Copyright © 2011-2022 走看看