Disable screen rotation in Qt

心已入冬 提交于 2019-12-25 09:20:06

问题


Is there a simple way to disable screen rotation in Qt for whole app? I just don't want to worry about that and simply disable it.

I am using Qt 5.8 and targeting Windows.


回答1:


It's pointless, because screen rotation from your perspective is the same as a screen resolution change, and if you turn that off, your users will be rightly hating you.

If you wish to test your code for compatibility with screen rotation, emulate it by changing screen resolution.




回答2:


The best way would be to disable rotation in Windows. The only other way I see is to display your widgets/qml rotated according to the current device orientation. Here is a code for obtaining current orientation under Windows (tested on Windows 8.1 tablet):

#include <Windows.h>

enum class EOrientation
{
  Rotate_0,
  Rotate_90,
  Rotate_180,
  Rotate_270
};

EOrientation CYourViewManager::getOrientation() const
{
  DEVMODE deviceMode;

  if (!EnumDisplaySettings(NULL, 0, &deviceMode))
    return EOrientation::Rotate_0;

  switch (deviceMode.dmDisplayOrientation)
  {
    case DMDO_90:
      return EOrientation::Rotate_90;

    case DMDO_180:
      return EOrientation::Rotate_180;

    case DMDO_270:
      return EOrientation::Rotate_270;
  }

  return EOrientation::Rotate_0;
}


来源:https://stackoverflow.com/questions/43864745/disable-screen-rotation-in-qt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!