- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我看过官方Qt documentation以及 StackOverflow 上关于 Qt 中高 DPI 支持的许多文章和问题。他们都专注于移植旧的应用程序并让它们以尽可能少的更改工作。
但是,如果我要启动一个全新的应用程序,并打算支持每个显示器的 DPI 感知应用程序,那么最好的方法是什么?
如果我理解正确,Qt::AA_EnableHighDpiScaling
与我想要的完全相反。我实际上应该禁用 HighDpiScaling 并在运行时手动计算所有尺寸?
许多建议说根本不使用尺寸,而是使用 float 布局。但在许多情况下,至少需要存在最小宽度和/或最小高度。由于 Qt Designer 只允许我将值放在绝对像素中,那么正确的方法是什么?如果显示器分辨率发生变化,我应该在哪里放置代码以重新计算尺寸?
或者我应该只使用自动缩放?
在我尝试添加 HighDPI 支持的一个较旧的应用程序中,我使用了这种方法 - 列出 DOM 的所有子级,并在给定某个比率的情况下一一调整它们的大小。 Ratio = 1 将产生与我在 Qt Designer 中指定的尺寸相同的尺寸。
void resizeWidgets(MyApp & qw, qreal mratio)
{
// ratio to calculate correct sizing
qreal mratio_bak = mratio;
if(MyApp::m_ratio != 0)
mratio /= MyApp::m_ratio;
// this all was done so that if its called 2 times with ratio = 2, total is not 4 but still just 2 (ratio is absolute)
MyApp::m_ratio = mratio_bak;
QLayout * ql = qw.layout();
if (ql == NULL)
return;
QWidget * pw = ql->parentWidget();
if (pw == NULL)
return;
QList<QLayout *> layouts;
foreach(QWidget *w, pw->findChildren<QWidget*>())
{
QRect g = w->geometry();
w->setMinimumSize(w->minimumWidth() * mratio, w->minimumHeight() * mratio);
w->setMaximumSize(w->maximumWidth() * mratio, w->maximumHeight() * mratio);
w->resize(w->width() * mratio, w->height() * mratio);
w->move(QPoint(g.x() * mratio, g.y() * mratio));
}
foreach(QLayout *l, pw->findChildren<QLayout*>())
{
if(l != NULL && !(l->objectName().isEmpty()))
layouts.append(l);
}
foreach(QLayout *l, layouts) {
QMargins m = l->contentsMargins();
m.setBottom(m.bottom() * mratio);
m.setTop(m.top() * mratio);
m.setLeft(m.left() * mratio);
m.setRight(m.right() * mratio);
l->setContentsMargins(m);
l->setSpacing(l->spacing() * mratio);
if (l->inherits("QGridLayout")) {
QGridLayout* gl = ((QGridLayout*)l);
gl->setHorizontalSpacing(gl->horizontalSpacing() * mratio);
gl->setVerticalSpacing(gl->verticalSpacing() * mratio);
}
}
QMargins m = qw.contentsMargins();
m.setBottom(m.bottom() * mratio);
m.setTop(m.top() * mratio);
m.setLeft(m.left() * mratio);
m.setRight(m.right() * mratio);
// resize accordingly main window
qw.resize(qw.width() * mratio, qw.height() * mratio);
qw.setContentsMargins(m);
qw.adjustSize();
}
从main调用:
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MyApp w;
// gets DPI
qreal dpi = a.primaryScreen()->logicalDotsPerInch();
MyApp::resizeWidgets(w, dpi / MyApp::refDpi);
w.show();
return a.exec();
}
我认为这不是一个好的解决方案。鉴于我刚开始,我可以根据最新的 Qt 标准完全自定义我的代码,我应该使用什么方法来获取 HighDPI 应用程序?
最佳答案
If I were to start a brand new application, with the intention to support per-monitor DPI awareness, what is the best approach?
我们不依赖 Qt 在每显示器 DPI 感知模式下进行自动缩放。至少设置了 Qt::AA_EnableHighDpiScaling
的基于 Qt 5.7 的应用程序不会这样做,并且无论像素密度如何,“高 DPI 缩放”更准确地绘制。
并且要调用每个显示器的 DPI 感知模式,您需要在项目可执行文件所在的同一目录中修改 Qt.conf
文件:
[Platforms]
# 1 - for System DPI Aware
# 2 - for Per Monitor DPI Aware
WindowsArguments = dpiawareness=2
# May need to define this section as well
#[Paths]
#Prefix=.
If I understand correctly, Qt::AA_EnableHighDpiScaling is the very opposite of what I want. I should actually disable HighDpiScaling and calculate all the dimensions manually on runtime?
不,这不是相反的东西,而是不同的东西。有几个 Qt 错误已作为无错误关闭:QTBUG-55449和 QTBUG-55510显示该功能背后的意图。顺便说一句,有QTBUG-55510提供了一种编程解决方法,用于在不修复 qt.conf
的情况下设置 Qt DPI 感知(自行决定使用,因为它使用“私有(private)”Qt 实现类来更改接口(interface),而不会通知较新的 Qt 版本)。
您还表达了在每显示器 DPI 感知模式下进行缩放的正确方法。不幸的是,除了当时没有太多的选择。但是,当窗口从一个监视器移动到另一个监视器时,有编程方法可以帮助处理窗口缩放的事件。这个问题开头的 resizeWidget
(一个,不是很多)之类的方法应该使用类似(Windows)的方法调用:
// we assume MainWindow is the widget dragged from one monitor to another
bool MainWindow::nativeEvent(const QByteArray& eventType, void* message, long* result)
{
MSG* pMsg = reinterpret_cast<MSG*>(message);
switch (pMsg->message)
{
case WM_DPICHANGED:
// parameters TBD but mind that 'last' DPI is in
// LOWORD(pMsg->wParam) and you need to detect current
resizeWidget(monitorRatio());
break;
这是一个相当困难和麻烦的方法,我通过让用户选择模式并重新启动应用程序进程(修复 qt. conf
或在应用程序启动时从 QTBUG-55510 执行解决方法)。我们希望 Qt 公司意识到需要针对小部件自动缩放的每显示器 DPI 感知模式。为什么我们需要它(?)是另一个问题。在我的情况下,我在自己的应用小部件 Canvas 中进行了每个显示器的渲染,应该可以缩放。
起初,阅读@selbie 对这个问题的评论,我意识到也许有一种方法可以在应用启动时尝试设置 QT_SCREEN_SCALE_FACTORS:
QT_SCREEN_SCALE_FACTORS [list] specifies scale factors for each screen. This will not change the size of point sized fonts. This environment variable is mainly useful for debugging, or to work around monitors with wrong EDID information(Extended Display Identification Data).
然后我读到 Qt blog关于如何应用多个屏幕因素并尝试对 4K 和 1080p 显示器执行以下操作,其中 4K 排在首位(主要)。
qputenv("QT_SCREEN_SCALE_FACTORS", "2;1");
这确实有点帮助:几乎正确的渲染但是在将窗口从一个监视器移动到另一个监视器时引入了窗口大小的缺陷,就像 QTBUG-55449做。如果客户将当前的应用程序行为视为错误(我们通过 System DPI Aware 为所有显示器 DPI 创建相同的基础),我想我会使用 WM_DPICHANGED
+ QT_SCREEN_SCALE_FACTORS
方法。 Qt 还没有现成可用的解决方案。
关于c++ - 如何着手开发新的 Qt 5.7+ High-DPI Per Monitor DPI Aware 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39823918/
从下面的链接中读取,我相信当 Nifi 集群中的一个节点出现故障时,数据将不会被处理,直到该节点恢复运行 --- 因此由故障节点处理的流文件/数据不会被另一个节点接管集群中的节点。 https://c
我在这两篇论文中发现了“high-capacity cnn”这个短语: 1. Rich feature hierarchies for accurate object detection and se
目前我想使用来自 http://codepen.io/JaxoDI/pen/DtsdH 的评级系统.但目前它在您从右向左悬停时有效。请随意在给定的链接中尝试一下。但我想要一个从左到右悬停的评级系统。
我读过多篇文章,包括 Jon Bentley 的二分查找章节。这是我对 CORRECT 二进制搜索逻辑的理解,它在我所做的简单测试中有效: binarysearch (arr, low, high,
我的问题与下面的有点不同 CSS Float Logic .我的问题是关于 height 比这更具体的概念。 这里有规则 https://www.w3.org/TR/CSS22/visuren.htm
当我们说“高阶”函数时,我怀疑“阶”的真正含义是什么?例如,我有一个嵌入式函数调用: f.g.h 那么它叫“三阶”函数吗? “高阶”函数是静态函数累加的概念吗?然后当我有一个递归函数 f 时,在运行时
我正在研究树问题 Convert Sorted Array to Binary Search Tree - LeetCode Given an array where elements are sor
我最近将 iPhone 设备中的 iOS 升级到 12.2(为我的应用程序“Match4app”提供对最新版本的支持),这似乎与 Xcode 10.1 不兼容。我应该将 Xcode 更新到 10.2
我了解 >>> 修复了溢出:当添加两个大的正长时,您最终可能会得到一个负数。有人能解释一下这种按位移位如何神奇地解决溢出问题吗?它与 >> 有何不同? 我的怀疑:我认为这与 Java 使用二进制补码这
我有一个关于托管高流量 Rails 应用程序的问题。问题是我有 3/4 年的 Ruby on Rails 应用程序经验,但我以前从未有过高流量网站。我真的很兴奋,因为这对我和我的同事来说是“下一个层次
人们说 Delphi 在整数运算上生成了非常好的优化代码。我在 Delphi 2007 中尝试了以下示例,并看到编译器生成的汇编代码。 program p1000; {$APPTYPE CONSOLE
我目前正在构建一个混合云解决方案,需要将消息写入队列以供稍后处理。队列具有高可用性(99.999+% 的正常运行时间)是绝对必要的。 我的选择是将消息读/写到本地 ZeroMQ 高可用性对或 Azur
我正在使用 Highcharts 创建此条形图。条形的对齐方式不在部分的中间(就像第一个红色条形图不在 2016 年 1 月的中间)。是否有任何选项可以将所有栏放置在每个部分的中间? 最佳答案 我找到
我一直在阅读 Framework Design Guidelines 一书,这是一本关于在 .NET 中设计框架的书,其中摘录了框架设计者对每个部分(例如参数设计、异常处理等)所做的决定。 在参数设计
我正在尝试停止Macbook上的Apache服务器。 我尝试了以下 $ sudo apachectl stop /System/Library/LaunchDaemons/org.apache.htt
如何在高可用性中部署 apache Airflow (正式称为 airbnb 的 Airflow )调度程序? 我不是在询问显然应该在高可用性配置中部署的后端 DB 或 RabbitMQ。 我的主要关
我的内部循环包含一个计算,分析显示有问题。 这个想法是采用灰度像素 x (0 .5,x =0)-1, ... x, erf(x), ... x, tanh(x), .
我们如何定制 HighChart 的 Bubble Chart具有不同的形状。 就像我们代表 4 种不同的事件类型一样,我们不仅需要 4 种不同颜色的气泡,而且还需要每个气泡具有不同的形状,如圆形、三
刚刚注意到我在 Azure 中的文件共享存储出现“ClientOtherError”的概率非常高。他们的成功率在 50-100% 之间。 有人有任何经验可以解释为什么会这样吗? 所附图表以红色/橙色显
我是Elasticsearch的新手,遇到了一个问题,甚至在故障排除方面也遇到了困难。我的Elasticsearch(1.1.1)当前正在使CPU处于运行状态,即使没有进行搜索或建立索引也是如此。 C
我是一名优秀的程序员,十分优秀!