如何获得当前屏幕缩放的比例
Tofloor
poster avatar
sd3252
deepin
2018-12-14 19:15
Author
我写了个小程序,界面一直不对,请问如何获得deepin系统当前缩放的比例值。


Reply Favorite View the author
All Replies
avatar
ruomeng
deepin
2018-12-14 19:39
#1
本帖最后由 ruomeng 于 2018-12-14 11:52 编辑

使用QT的方法使用QApplication::screen()获取QScreen然后查询devicePixelRatio

示例代码


#include
#include
#include
#include

int main(int argc, char *argv[]) {
    QApplication app(argc, argv);
    QWidget w;


    QList desktop = QApplication::screens();
    QLabel * label = new QLabel(&w);
    QString str = "当前窗口的缩放值为: " + QString::number( desktop.at(0)->devicePixelRatio()) ;
    label->setText(str);
    label->adjustSize();
    w.move(500, 300);
    w.show();
    return app.exec();
}

Reply View the author
avatar
ruomeng
deepin
2018-12-14 19:40
#2
本帖最后由 ruomeng 于 2018-12-14 11:43 编辑

啊,这是qt写的,你要是不用qt,我也不清楚了,简单点可以在设置显示里看到啊

Reply View the author
avatar
sd3252
deepin
2018-12-14 22:35
#3
https://bbs.deepin.org/post/172414
使用QT的方法使用QApplication::screen()获取QScreen然后查询devicePixelRatio

示例代码

好的谢谢您。
Reply View the author