본문 바로가기

QT/QT 4.6.2

컴퓨터 해상도 구하기(QDesktopWidget::screenGeometry)


내가 책을 보면서도 컴퓨터 해상도를 구하기를 찾지 못하여 결국은

Qt Assistant에서 찾아 보았다.

일단 아는 정보가 없기 때문에 Screen이라는 검색어로 찾아 보니 결국은 있었다.

간단한 예제 소스를 보게 되면,

#include 
#include 
#include 

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QMessageBox *box = new QMessageBox;
    QString str;
    int widthNumber;
    int heightNumber;

    widthNumber = QApplication::desktop()->screenGeometry().width();
    heightNumber = QApplication::desktop()->screenGeometry().height();

    str.sprintf("%d %d",widthNumber, heightNumber);

    box->setText(str);
    box->show();

    return app.exec();
}


이런식으로 구현을 하였다.

그래서 결과 화면을 보면


이렇게 실제 해상도와 같다는 것을 확인 하였다.

간단히 소스 분석을 하면, 

일단 QApplication::desktop()->screenGeometry() 이 함수로 해상도를 구하고

str.sprintf("%d %d",widthNumber, heightNumber);

이 작업으로 변수 값들을 문자열로 바꾸었다.