【问题标题】:Manage multiple displays管理多个显示器
【发布时间】:2019-06-18 19:04:43
【问题描述】:

我正在使用 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% 的屏幕宽度显示。

【问题讨论】:

  • 罚款是什么意思?无论屏幕分辨率或尺寸如何,尺寸都一样?
  • 您是否尝试过使用QDesktopWidget::screenNumber()
  • 问题已更新。我还没有尝试过 QDesktopWidget::screenNumber()。
  • 我注意到QDesktopWidget 大部分已被弃用,我建议您改用QScreen,它表示单个物理屏幕,您可以使用QGuiApplication::primaryScreen() 获取实例,然后获取其几何图形与QScreen::geometry()。让我知道这是否有效,以便我将其发布为答案。
  • 如果您从窗口管理器中选择“复制显示”,则没有辅助屏幕。缩放由您的操作系统完成。

标签: c++ qt


【解决方案1】:

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

为此,我需要第二张高分辨率图像 说“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));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多