title: Why doesn't Qt::AA_DisableHighDpiScaling disable high DPI scaling, and why does Qt::AA_EnableHighDpiScaling disable it?
body: <p>I'm working on a Qt application (deploying to Qt 5.11, but I'm testing on Qt 5.14) that needs to run on a variety of projectors. At least one of these projectors reports a physical size of over one metre, which results in only 32.5 dpi reported to the Linux OS (compared to the default of 96 dpi). The effect of this setting on our Qt app is that all text becomes unreadably small:</p>
  
  <p><a href="https://i.stack.imgur.com/3gs7d.png" rel="noreferrer"><img src="https://i.stack.imgur.com/3gs7d.png" alt="Screenshot of problem"></a></p>
  
  <p>It can be reproduced on any system by running</p>
  
  <pre><code>xrandr --dpi 32.5
  </code></pre>
  
  <p>before starting the application.</p>
  
  <p>We could configure the system dpi differently, but there are reasons not to: this dpi is actually in the right ballpark (it's even too high), we may want to use it in other applications, and customers may use their own projector which might break our manual configuration.</p>
  
  <p>The safe approach for this particular use case is to pretend we're still living in the stone age: ignore the system dpi setting and just use a 1:1 mapping between device-independent pixels and device pixels. The <a href="https://doc.qt.io/qt-5/highdpi.html" rel="noreferrer">High DPI displays</a> documentation says:</p>
  
  <blockquote>
    <p>The <code>Qt::AA_DisableHighDpiScaling</code> application attribute, introduced in Qt 5.6, turns off all scaling. This is intended for applications that require actual window system coordinates, regardless of environment variables. This attribute takes priority over <code>Qt::AA_EnableHighDpiScaling</code>.</p>
  </blockquote>
  
  <p>So I added this as the first line in <code>main</code> (before the <code>QApplication</code> is created):</p>
  
  <pre><code>QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling);
  </code></pre>
  
  <p>However, it seems to have no effect; text is still unreadably small. I also tried this in various combinations with:</p>
  
  <pre><code>QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling, false);
  QCoreApplication::setAttribute(Qt::AA_Use96Dpi);
  </code></pre>
  
  <p>Nothing has any visible effect effect.</p>
  
  <p>What <em>does</em> work is setting <code>QT_AUTO_SCREEN_SCALE_FACTOR=1</code> in the environment. If I understand correctly, this would <em>enable</em> scaling rather than disable it, but setting it to <code>0</code> does not work!</p>
  
  <p>Similarly, if I <em>enable</em> <code>Qt::AA_EnableHighDpiScaling</code> in code like this, everything becomes readable:</p>
  
  <pre><code>QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
  </code></pre>
  
  <p>What also works to some extent is hardcoding the font size (found <a href="https://wiki.qt.io/Technical_FAQ#How_can_I_prevent_the_font_from_scaling_up_when_the_DPI_is_increased.3F" rel="noreferrer">here</a>): </p>
  
  <pre><code>QFont font = qApp-&gt;font();
  font.setPixelSize(11);
  qApp-&gt;setFont(font);
  </code></pre>
  
  <p>However, margins in the layout still seem to be scaled, so this results in a very cramped (albeit usable) layout.</p>
  
  <p>What also works is setting <code>QT_FONT_DPI=96</code> in the environment (this variable seems to be undocumented, but it works in Qt 5.11 and 5.14 at least).</p>
  
  <p>Either there are bugs in Qt, or more likely, I'm misunderstanding something. How come that enabling the scaling seems to disable it and vice versa?</p>
  
  <hr>
  
  <p>Edit: just tested on Qt 5.11 too, although it's on another system. There, neither <code>QT_AUTO_SCREEN_SCALE_FACTOR=1</code> nor <code>QT_AUTO_SCREEN_SCALE_FACTOR=0</code> works, so it seems we are dealing with Qt bugs to some extent after all. Maybe related:</p>
  
  <ul>
  <li><a href="https://bugreports.qt.io/browse/QTBUG-55654" rel="noreferrer">High DPI scaling not working correctly</a> - CLOSED Out of scope</li>
  <li><a href="https://bugreports.qt.io/browse/QTBUG-53022" rel="noreferrer">HighDPi: Update scale factor setting for devicePixelRatio scaling (AA_EnableHighDpiScaling)</a> - CLOSED Done in 5.14</li>
  <li><a href="https://bugreports.qt.io/browse/QTCREATORBUG-16293" rel="noreferrer">Support of DPI Scaling Level for Displays in Windows 10</a> - REPORTED Unresolved</li>
  <li><a href="https://bugreports.qt.io/browse/QTBUG-67928" rel="noreferrer">Qt uses wrong source for logical DPI on X</a> - REPORTED Unresolved - <strong>This may be the root cause of the issue I'm seeing.</strong></li>
  <li><a href="https://bugreports.qt.io/browse/QTBUG-65061" rel="noreferrer">Uselessness of setAttribute(Qt::AA_EnableHighDpiScaling)</a> - REPORTED Unresolved</li>
  </ul>
  
  <p>So how can I make it work reliably in all cases?</p>