无法使用 Qt4 over RDP (RemoteApp) 打开最大化 window
Can't open maximized window using Qt4 over RDP (RemoteApp)
我正在使用 PyQt4 4.11.4 (Qt 4.8.7) 和 Python 2.7.12 编写应用程序。当 运行 它使用 RemoteApp(内置 Windows 远程桌面服务)时,我无法 windows 以最大化状态打开:它显示为几个(单个?)帧最大化,并立即跳转到恢复状态。
重现错误的代码:
from PyQt4.QtGui import QApplication, QDialog
from PyQt4.QtCore import Qt
import sys
app = QApplication(sys.argv)
w = QDialog()
w.setWindowFlags(Qt.Window)
w.showMaximized()
w.show()
sys.exit(app.exec_())
无法使用 Python 2.6.4 和 Qt 4.5.3 重现错误(应用程序是使用 PyInstaller 构建的,我找不到获取 PyQt 版本的方法)。
我发现的唯一提到的类似错误(不确定是否相同)是 here。
是否有任何修复此错误的方法?我不考虑使用旧的 Qt 版本作为解决方案。
UP1:
上面用 C++ 重写的代码片段产生了相同的行为,因此这是一个 Qt 错误。
UP2:
Windows 在 Qt 4.8 中有 WS_POPUP
和 WS_combine_POPUPWINDOW
样式,而在 Qt 4.5 中则没有。修复 this one.
时可能引入的错误
UP3:
是的,问题出在 WS_POPUP
风格上。手动删除后 window 保持最大化:
...
HWND hWnd = w.winId();
long style = GetWindowLong(hWnd, GWL_STYLE);
SetWindowLong(hWnd, GWL_STYLE, style & ~WS_POPUP);
...
正在搜索不同的删除方法...
通过还原此补丁并重建 Qt 解决了问题:
diff --git a/src/gui/kernel/qwidget_win.cpp b/src/gui/kernel/qwidget_win.cpp
index 39ed750..c358b9b 100644
--- a/src/gui/kernel/qwidget_win.cpp
+++ b/src/gui/kernel/qwidget_win.cpp
@@ -329,18 +329,11 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO
if (topLevel) {
if ((type == Qt::Window || dialog || tool)) {
if (!(flags & Qt::FramelessWindowHint)) {
- if (!(flags & Qt::MSWindowsFixedSizeDialogHint)) {
+ style |= WS_POPUP;
+ if (!(flags & Qt::MSWindowsFixedSizeDialogHint))
style |= WS_THICKFRAME;
- if(!(flags &
- ( Qt::WindowSystemMenuHint
- | Qt::WindowTitleHint
- | Qt::WindowMinMaxButtonsHint
- | Qt::WindowCloseButtonHint
- | Qt::WindowContextHelpButtonHint)))
- style |= WS_POPUP;
- } else {
- style |= WS_POPUP | WS_DLGFRAME;
- }
+ else
+ style |= WS_DLGFRAME;
}
if (flags & Qt::WindowTitleHint)
style |= WS_CAPTION;
@@ -424,6 +417,14 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO
if (!q->testAttribute(Qt::WA_Resized)) {
w = sw/2;
h = 4*sh/10;
+ if (extra) {
+ int dx = rect.right - rect.left;
+ int dy = rect.bottom - rect.top;
+ w = qMin(w, extra->maxw + dx);
+ h = qMin(h, extra->maxh + dy);
+ w = qMax(w, extra->minw + dx);
+ h = qMax(h, extra->minh + dy);
+ }
}
if (!wasMoved) {
x = sw/2 - w/2;
找到here
我正在使用 PyQt4 4.11.4 (Qt 4.8.7) 和 Python 2.7.12 编写应用程序。当 运行 它使用 RemoteApp(内置 Windows 远程桌面服务)时,我无法 windows 以最大化状态打开:它显示为几个(单个?)帧最大化,并立即跳转到恢复状态。 重现错误的代码:
from PyQt4.QtGui import QApplication, QDialog
from PyQt4.QtCore import Qt
import sys
app = QApplication(sys.argv)
w = QDialog()
w.setWindowFlags(Qt.Window)
w.showMaximized()
w.show()
sys.exit(app.exec_())
无法使用 Python 2.6.4 和 Qt 4.5.3 重现错误(应用程序是使用 PyInstaller 构建的,我找不到获取 PyQt 版本的方法)。
我发现的唯一提到的类似错误(不确定是否相同)是 here。
是否有任何修复此错误的方法?我不考虑使用旧的 Qt 版本作为解决方案。
UP1: 上面用 C++ 重写的代码片段产生了相同的行为,因此这是一个 Qt 错误。
UP2:
Windows 在 Qt 4.8 中有 WS_POPUP
和 WS_combine_POPUPWINDOW
样式,而在 Qt 4.5 中则没有。修复 this one.
UP3:
是的,问题出在 WS_POPUP
风格上。手动删除后 window 保持最大化:
...
HWND hWnd = w.winId();
long style = GetWindowLong(hWnd, GWL_STYLE);
SetWindowLong(hWnd, GWL_STYLE, style & ~WS_POPUP);
...
正在搜索不同的删除方法...
通过还原此补丁并重建 Qt 解决了问题:
diff --git a/src/gui/kernel/qwidget_win.cpp b/src/gui/kernel/qwidget_win.cpp
index 39ed750..c358b9b 100644
--- a/src/gui/kernel/qwidget_win.cpp
+++ b/src/gui/kernel/qwidget_win.cpp
@@ -329,18 +329,11 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO
if (topLevel) {
if ((type == Qt::Window || dialog || tool)) {
if (!(flags & Qt::FramelessWindowHint)) {
- if (!(flags & Qt::MSWindowsFixedSizeDialogHint)) {
+ style |= WS_POPUP;
+ if (!(flags & Qt::MSWindowsFixedSizeDialogHint))
style |= WS_THICKFRAME;
- if(!(flags &
- ( Qt::WindowSystemMenuHint
- | Qt::WindowTitleHint
- | Qt::WindowMinMaxButtonsHint
- | Qt::WindowCloseButtonHint
- | Qt::WindowContextHelpButtonHint)))
- style |= WS_POPUP;
- } else {
- style |= WS_POPUP | WS_DLGFRAME;
- }
+ else
+ style |= WS_DLGFRAME;
}
if (flags & Qt::WindowTitleHint)
style |= WS_CAPTION;
@@ -424,6 +417,14 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO
if (!q->testAttribute(Qt::WA_Resized)) {
w = sw/2;
h = 4*sh/10;
+ if (extra) {
+ int dx = rect.right - rect.left;
+ int dy = rect.bottom - rect.top;
+ w = qMin(w, extra->maxw + dx);
+ h = qMin(h, extra->maxh + dy);
+ w = qMax(w, extra->minw + dx);
+ h = qMax(h, extra->minh + dy);
+ }
}
if (!wasMoved) {
x = sw/2 - w/2;
找到here