了解Qt QScreen的geometry ,size

目的

了解qt 对于屏幕的size, geometry含义, 更能有效实现最大化, 向下还原逻辑操作

Test

目前我有两个屏 ,1920x1080, 3840*2160.
检测当前程序所在screen(1920x1080)下属性

int screenNum =  qApp->desktop()->screenNumber(this);
    if(screenNum >= 0){
        QScreen* screen = qApp->screens().at(screenNum);
        qInfo() << "screen devicePixelRatio: " << screen->devicePixelRatio() << "screen logicalDotsPerInch: " << screen->logicalDotsPerInch() << "screen physicalDotsPerInch: " << screen->physicalDotsPerInch()
                << "screen physicalSize: " << screen->physicalSize() << "screen availableSize: " << screen->availableSize() << "screen availableVirtualSize: " << screen->availableVirtualSize() << "screen size: " << screen->size()
                << "screen availableGeometry: " << screen->availableGeometry() << "screen availableVirtualGeometry: " << screen->availableVirtualGeometry()
                << "screen virtualGeometry: " << screen->virtualGeometry() << "screen geometry: " << screen->geometry() << screen->geometry().size();
    }

打印结果

screen devicePixelRatio: 1 screen logicalDotsPerInch: 96 screen physicalDotsPerInch: 92.6073 screen physicalSize: QSizeF(527, 296) screen availableSize: QSize(1920, 1040) screen availableVirtualSize: QSize(5760, 2080) screen size: QSize(1920, 1080) screen availableGeometry: QRect(0,0 1920x1040) screen availableVirtualGeometry: QRect(-3840,-515 5760x2080) screen virtualGeometry: QRect(-3840,-515 5760x2160) screen geometry: QRect(0,0 1920x1080) QSize(1920, 1080)

移除任务栏后:

screen devicePixelRatio: 1 screen logicalDotsPerInch: 96 screen physicalDotsPerInch: 92.6073 screen physicalSize: QSizeF(527, 296) screen availableSize: QSize(1920, 1080) screen availableVirtualSize: QSize(5760, 2160) screen size: QSize(1920, 1080) screen availableGeometry: QRect(0,0 1920x1080) screen availableVirtualGeometry: QRect(-3840,-515 5760x2160) screen virtualGeometry: QRect(-3840,-515 5760x2160) screen geometry: QRect(0,0 1920x1080) QSize(1920, 1080)

结果你会发现 screen availableSize: 高度增加了40px。screen availableGeometry: QRect(0,0 1920x1040) 也是。而实际的screen geometry: QRect(0,0 1920x1080) QSize(1920, 1080), 与物理size没有改变。只有充分知道QScreen相关属性, 才能更好写出多屏下相关处理操作。

你可能感兴趣的:(qt)