管理多个显示器

Manage multiple displays

本文关键字:显示器 管理      更新时间:2023-10-16

我正在使用QSplashScreen为我的QtQuick 2应用程序显示初始屏幕。

 QScreen *screen = QGuiApplication::primaryScreen();
 QRect  screen_geometry = screen->geometry();
 int screen_width = screen_geometry.width();
 QPixmap pixmap("splash.png");
 QSplashScreen splash(pixmap.scaledToWidth(screen_width*0.35,Qt::SmoothTransformation));

screen_width用于缩放图像。我的笔记本电脑已连接到 2K 显示器。

问题是,对于不同的"显示管理选项",图像的显示方式不同,例如

">

仅限PC","重复显示"和"仅第二屏幕"。

我的问题是,如何管理两个显示器,以使图像在两个显示器上都显示良好。

我所需要的只是以 35% 的屏幕宽度显示初始屏幕。它应该在两个显示器中以 35% 的屏幕宽度显示。

我不知道

我的问题的确切解决方案。但这是我目前正在做的事情。

为此,我需要辅助高分辨率图像说"splash@2x.png">

参考: https://doc.qt.io/qt-5/scalability.html#loading-files-depending-on-platform

 QScreen *screen = QGuiApplication::primaryScreen();
 QRect  screen_geometry = screen->geometry();
 int DPR = static_cast<int>(screen->devicePixelRatio()); // 1 or 2
 int screen_width = screen_geometry.width();
 QString splash_screen_image= "splash.png";
 if(DPR == 2)
 {
    //2K screen connected directly to PC
    splash_screen_image= "splash@2x.png";
    screen_width*=2;
 }
 if(DPR == 1 && screen_width >1920)
 {
    //'Second screen only' selected when laptop is connected to 2K display
    splash_screen_image= "splash@2x.png";
    screen_width*=2;
 }
 if(DPR == 1 && screen_width <=1920)
 {
    //'Duplicate display' or 'PC only' selected when laptop is connected to 2K display
    // or Desktop PC connected to HD monitor
    //Use "splash.png"
 }
 QPixmap pixmap(splash_screen_image);
 QSplashScreen splash(pixmap.scaledToWidth(screen_width*0.35,Qt::SmoothTransformation));