pythonqtqt4pyqt4remoteapp

Can't open maximized window using Qt4 over RDP (RemoteApp)


I'm writing an app using PyQt4 4.11.4 (Qt 4.8.7) and Python 2.7.12. When running it using RemoteApp (built-in Windows Remote Desktop service) I couldn't get windows to open in maximized state: it appears maximized for a few (single?) frames, and jumps to restored state immediately. Code to reproduce bug:

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_())

Bug couldn't be reproduced with Python 2.6.4 and Qt 4.5.3 (app is built with PyInstaller and I can't find a way to get PyQt version).

The only mention of similiar bug (not sure if same) I found is here.

Is there any fix for this bug? I don't consider using older Qt version as solution.

UP1: The snippet above rewritten in C++ produces the same behavior, so it's a Qt bug.

UP2: Windows in Qt 4.8 have WS_POPUP and WS_combine_POPUPWINDOW styles, while in Qt 4.5 they don't. Bug possibly introduced while fixing this one.

UP3: Yes, the problem is in WS_POPUP style. After manually removing it window stays maximized:

...
HWND hWnd = w.winId();
long style = GetWindowLong(hWnd, GWL_STYLE);
SetWindowLong(hWnd, GWL_STYLE, style & ~WS_POPUP);
...

Searching different way to remove it...


Solution

  • Problem solved by reverting this patch and rebuilding 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;
    

    found here