Fix build for old Qt versions.

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2020-10-19 18:24:38 +08:00
parent af65f2d9e3
commit 47910161c9
3 changed files with 20 additions and 0 deletions

View File

@ -127,7 +127,15 @@ void FramelessHelper::moveWindowToDesktopCenter(QObject *obj)
else if (obj->isWidgetType()) {
const auto widget = qobject_cast<QWidget *>(obj);
if (widget && widget->isTopLevel()) {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
const QSize ss = widget->screen()->size();
#else
QSize ss = {};
QWindow *window = widget->windowHandle();
if (window) {
ss = window->screen()->size();
}
#endif
const int sw = ss.width();
const int sh = ss.height();
const int ww = widget->width();

View File

@ -57,7 +57,12 @@ QScreen *getCurrentScreenFromWindow(QObject *window)
}
#ifdef QT_WIDGETS_LIB
else if (window->isWidgetType()) {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
return qobject_cast<QWidget *>(window)->screen();
#else
QWindow *win = qobject_cast<QWidget *>(window)->windowHandle();
return win ? win->screen() : nullptr;
#endif
}
#endif
else {

View File

@ -1151,7 +1151,14 @@ QString getCurrentScreenIdentifier(const HWND handle)
#ifdef QT_WIDGETS_LIB
const QWidget *widget = QWidget::find(reinterpret_cast<WId>(handle));
if (widget && widget->isTopLevel()) {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
currentScreen = widget->screen();
#else
QWindow *window = widget->windowHandle();
if (window) {
currentScreen = window->screen();
}
#endif
}
#endif
if (!currentScreen) {