8

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?

sashoalm
  • 75,001
  • 122
  • 434
  • 781
Srv19
  • 3,458
  • 6
  • 44
  • 75
  • 1
    QWizard inherits from QDialog, this problem is general for all QDialogs. See https://stackoverflow.com/questions/4699808/cant-add-minimize-button-to-qdialog-under-linux, I had asked a similar question before. – sashoalm Feb 04 '15 at 11:02
  • As you can see from the code snippet, i am aware of that solution. I can only repeat that it doesn't do what i need: with those flags set maximize button is displayed, but not enabled. – Srv19 Feb 04 '15 at 11:11
  • You are right, i should have been more clear in question. – Srv19 Feb 04 '15 at 11:20
  • Have you tried to call `setSizeGripEnabled(true)`? I mean: if it has a size-grip, it may be resized - which in turn means it should be maximizable... – St0fF Feb 04 '15 at 12:56
  • The window has size grip and is resizeable. However, maximize buttin is disabled. For an experiment, i tried whowing the window maximized. The button is still disabled (and does not change to "restore size" button. – Srv19 Feb 04 '15 at 13:12

4 Answers4

7

This works for me:

setWindowFlags(windowFlags() | Qt::CustomizeWindowHint |
                               Qt::WindowMinimizeButtonHint |
                               Qt::WindowMaximizeButtonHint |
                               Qt::WindowCloseButtonHint);

According to the documentation, you have to use the Qt::CustomizeWindowHint to be able to change the individual hints on the min/max buttons.

Luiz Vieira
  • 570
  • 11
  • 35
5

Someone here says this solved his problem:

setWindowFlags(Qt::Window);

  • 1
    With QWizard i do get minimize and maximize button with this flag, however maximizing button is still disabled. – Srv19 Feb 04 '15 at 15:22
2

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);
    }
};
Antonio Dias
  • 2,751
  • 20
  • 40
  • I was able to throw a wizard together quickly using qwizard; however the price i am paying for it is pain and frustration of being unable to (for example)change position of a page subtitle – Srv19 Feb 05 '15 at 07:54
0

I have this:

QWizard *wizard = new QWizard(this, Qt::CustomizeWindowHint | Qt::WindowMaximizeButtonHint | Qt::Window);
wizard->setSizeGripEnabled(true);

Running Windows 10 on my dev-box, Qt 5.5.1, working for me.

One of my pages is a big QTableWidget that ends up being like an Excel sheet of some sorts (a big page to verify and edit-in-place a lot of data). Making the window resizable and let the user maximize it if they want makes it much easier to work with, instead of having to constantly scroll in a small dialog.

Normally you would say: If you need such a big window, it probably shouldn't be in a QWizard. But in this case it's really the middle of a workflow thing. A big 'verify, edit-if-needed and continue' page so it would be weird to stop the QWizard before and then having to start another one after or something.