问题
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