Srv19 Srv19 - 28 days ago 26
C++ Question

Enable maximize button in QWizard

I have a Windows application that is built on QWizard (which inherits from QDialog). It must have a working maximization button.

By default maximization button is not even visible. i have set it to show, using:

auto flags = windowFlags();
flags ^= Qt::WindowContextHelpButtonHint;
flags |= Qt::WindowMinMaxButtonsHint;
setWindowFlags(flags);


However, it shows up disabled (grayed out, non-responding).

How can i enable it?

Answer

I believe that you'll get better results creating your own dialog, but if you really wanna do it, one way is use window styles (Windows only, not cross-plataform).

Wizard class example:

class wizard : public QWizard
{
public:
    wizard() {}
    ~wizard() {}

protected:
    bool event(QEvent *event)
    {
#ifdef Q_OS_WIN /*Make this code Windows OS only*/
        if (event->type() == QEvent::WinIdChange)
        {
            HWND hwnd = (HWND)winId();
            LONG lStyle = GetWindowLong(hwnd, GWL_STYLE);
            lStyle |= (WS_MINIMIZEBOX | WS_MAXIMIZEBOX); /*Enable minimize and maximize*/
            SetWindowLong(hwnd, GWL_STYLE, lStyle);
        }
#endif

        return QWizard::event(event);
    }
};