0

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.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
naide
  • 293
  • 3
  • 14
  • 2
    I'm sorry, but how is screen rotation an issue for a Windows app? I don't see how screen rotation would be an issue for any desktop platform? Thanks for enlightening me :-) – Danyright May 09 '17 at 13:14
  • @Danyright It's not an issue not because of desktops not changing screen orientation, but because screen rotation appears to an application just like a resolution change would. It's mostly immaterial, in other words. – Kuba hasn't forgotten Monica May 09 '17 at 15:05
  • I forgot to mention it's tablet application. – naide May 09 '17 at 17:22

2 Answers2

0

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;
}
Piotr S
  • 41
  • 6
0

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.

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313