在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\n",qPrintable(QString::number(screenrect.width())));
    qCritical("screenrect.h==%s\n",qPrintable(QString::number(screenrect.height())));
    qCritical("deskrect.w==%s\n",qPrintable(QString::number(deskrect.width())));
    qCritical("deskrect.h==%s\n",qPrintable(QString::number(deskrect.height())));
    qCritical("scrcount==%s\n",qPrintable(QString::number(scrcount)));

}

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM