转载:Qt应用程序采用双屏显示的一些想法

摘要:
重印地址:https://www.cnblogs.com/ppffs/p/3186221.html最近,由于项目的需要,用Qt开发的程序应该能够支持双屏显示。经过在线研究,我们发现http://www.ics.com/blog/whats-new-qt-5-qscreen-class#.Ud9mY4csnXB中讨论了Qt的多屏幕管理,并指出可以使用QScreen获取窗口的相关信息。代码如下:

 转载地址:https://www.cnblogs.com/ppffs/p/3186221.html

最近由于项目需要,采用Qt开发的程序要能够支持双屏显示,在网上调研了以下,发现网页http://www.ics.com/blog/whats-new-qt-5-qscreen-class#.Ud9mY4csnXB中对于Qt的多屏幕管理有一定论述,指出采用QScreen可以获取窗口的相关信息,代码如下:

复制代码
#include <QGuiApplication>
#include <QScreen>
#include <QDebug>

/*
  Example of using Qt 5 QScreen class.
*/

// Helper function to return display orientation as a string.
QString Orientation(Qt::ScreenOrientation orientation)
{
    switch (orientation) {
        case Qt::PrimaryOrientation           : return "Primary";
        case Qt::LandscapeOrientation         : return "Landscape";
        case Qt::PortraitOrientation          : return "Portrait";
        case Qt::InvertedLandscapeOrientation : return "Inverted landscape";
        case Qt::InvertedPortraitOrientation  : return "Inverted portrait";
        default                               : return "Unknown";
    }
}

int main(int argc, char *argv)
{
    QGuiApplication a(argc, &argv);

    qDebug() << "Number of screens:" << QGuiApplication::screens().size();

    qDebug() << "Primary screen:" << QGuiApplication::primaryScreen()->name();

    foreach (QScreen *screen, QGuiApplication::screens()) {
        qDebug() << "Information for screen:" << screen->name();
        qDebug() << "  Available geometry:" << screen->availableGeometry().x() << screen->availableGeometry().y() << screen->availableGeometry().width() << "x" << screen->availableGeometry().height();
        qDebug() << "  Available size:" << screen->availableSize().width() << "x" << screen->availableSize().height();
        qDebug() << "  Available virtual geometry:" << screen->availableVirtualGeometry().x() << screen->availableVirtualGeometry().y() << screen->availableVirtualGeometry().width() << "x" << screen->availableVirtualGeometry().height();
        qDebug() << "  Available virtual size:" << screen->availableVirtualSize().width() << "x" << screen->availableVirtualSize().height();
        qDebug() << "  Depth:" << screen->depth() << "bits";
        qDebug() << "  Geometry:" << screen->geometry().x() << screen->geometry().y() << screen->geometry().width() << "x" << screen->geometry().height();
        qDebug() << "  Logical DPI:" << screen->logicalDotsPerInch();
        qDebug() << "  Logical DPI X:" << screen->logicalDotsPerInchX();
        qDebug() << "  Logical DPI Y:" << screen->logicalDotsPerInchY();
        qDebug() << "  Orientation:" << Orientation(screen->orientation());
        qDebug() << "  Physical DPI:" << screen->physicalDotsPerInch();
        qDebug() << "  Physical DPI X:" << screen->physicalDotsPerInchX();
        qDebug() << "  Physical DPI Y:" << screen->physicalDotsPerInchY();
        qDebug() << "  Physical size:" << screen->physicalSize().width() << "x" << screen->physicalSize().height() << "mm";
        qDebug() << "  Primary orientation:" << Orientation(screen->primaryOrientation());
        qDebug() << "  Refresh rate:" << screen->refreshRate() << "Hz";
        qDebug() << "  Size:" << screen->size().width() << "x" << screen->size().height();
        qDebug() << "  Virtual geometry:" << screen->virtualGeometry().x() << screen->virtualGeometry().y() << screen->virtualGeometry().width() << "x" << screen->virtualGeometry().height();
        qDebug() << "  Virtual size:" << screen->virtualSize().width() << "x" << screen->virtualSize().height();
    }
}
复制代码

     于是,有了建立基于Qt的双屏显示程序的思路:建立两个QMainWindow,然后分别通过函数setGeometry分别指定两个QMainWindow为显示器一和显示器二的位置,这样总体的效果就是这个程序能够实现双屏的功能。同时需要注意,在定义QMainWindow的对象时,需要使用堆内存的方法,不能采用栈内存,在网页http://www.qtcentre.org/archive/index.php/t-16439.html中对此有过论述。

免责声明:文章转载自《转载:Qt应用程序采用双屏显示的一些想法》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇什么是系统封装ADO中记录集recordSet的使用下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"

功能:解决honeGap Html5 App 横竖屏切换问题 用法:需要在配置文件中如下配置: android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"...

iOS屏幕旋转 浅析

一、两种orientation 了解屏幕旋转首先需要区分两种orientation 1、device orientation 设备的物理方向,由类型UIDeviceOrientation表示,当前设备方向获取方式: 1 [UIDevice currentDevice].orientation 该属性的值一般是与当前设备方向保持一致的,但须注意以下几...

Android开发 设备横屏与竖屏的详解

需要了解横竖屏切换关键知识  1.在Android设备的横竖屏幕,每一次切换横竖屏其实是在重新创建Activity,Activity会重新走一遍生命周期.从onCreate 到 onDestroy   2.在Activity类里的变量也会重新创建,这点需要注意! 判断屏幕方向,方式一判断屏幕是否竖屏   @Override protected vo...

Android平台下利用zxing实现二维码开发

现在走在大街小巷都能看到二维码,而且最近由于项目需要,所以研究了下二维码开发的东西,开源的二维码扫描库主要有zxing和zbar,zbar 在iPos平台上应用比较成熟,而在Android平台上主流还是用zxing库,因此这里主要讲述如何利用zxing进行二维码开发。 1.如何将zxing的Android源码导入工程。   在导入zxing的android...

监听iOS检测屏幕旋转状态,不需开启屏幕旋转

-(void)rotation_icon:(float)n{ UIButton*history_btn=[self.viewviewWithTag:<#(NSInteger)#>][self.viewviewWithTagName:@"home_history"]; UIButton*cam_btn=[self.viewviewWithT...

IOS5,6,7不同版的适配. 强制旋转和自动旋转.

改变Orientation的三种途径 这里, 咱们主要理清一下: 到底有哪些设置可以改变屏幕旋转特性. 这样: 出现任何问题我们都可以从这几个途径中发现原因. 灵活应付产品经理的各种需求. 首先我们得知道: 当手机的重力感应打开的时候, 如果用户旋转手机, 系统会抛发UIDeviceOrientationDidChangeNotification ...