• 在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

  • 相关阅读:
    iOS 定位服务、通讯录、日历、提醒事项、照片、蓝牙共享、麦克风、相机等授权检测
    App项目升级Xcode7&iOS9(续)
    iOS 9之3D Touch
    iOS项目更新之升级Xcode7 & iOS9
    Android 5.0 之SwipeRefreshLayout
    Xcode7真机调试iOS应用程序
    iOS 9之WatchKit for WatchOS 2
    iOS 9之Shared Links Extension(Safari Extensibility)
    iOS多线程的初步研究(十)-- dispatch同步
    iOS多线程的初步研究(九)-- dispatch源
  • 原文地址:https://www.cnblogs.com/findumars/p/5578771.html
Copyright © 2020-2023  润新知