2

In my Qt application, I have a QMainWindow subclass for the UI (ProgramWindow) and a QDialog subclass (SettingsDialog) which is shown when the user clicks the "Settings" button in the main window. I'm using the following code to implement this:

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    ProgramWindow pw;
    pw.show();
    pw.setFixedSize(pw.size());

    SettingsDialog set(&pw);
    QObject::connect(&pw, SIGNAL(settingsButtonClicked()), &set, SLOT(show()));

    return a.exec();
}

However, I have noticed that when the settings dialog is shown for the second time (the user clicks the settings button, the dialog is shown, then the user closes it, then clicks on "Settings" again) the window is not shown "smoothly", as other windows are in Windows 8.1's default theme, it just suddenly appears on the screen like in the old XP theme, for example. Note that this doesn't happen the first time the window is shown.

What could be the reason?

EDIT: I suspect that instead of destroying the window, close() called on a QDialog will end up calling Win32's ShowWindow with the SW_HIDE parameter, and so when it's shown again later, the Windows UI manager doesn't see it as creating the window but merely re-showing it, so it doesn't "play" the animation. The solution is to create the dialog using new and letting Qt dispose of it when appropriate:

MyDialog* dialog = new MyDialog;
dialog->show();

// in MyDialog's constructor
setAttribute(Qt::WA_DeleteOnClose);
user4520
  • 3,401
  • 1
  • 27
  • 50
  • could be a bug. But how do you close the dialog?? – UmNyobe Oct 04 '15 at 09:10
  • @UmNyobe I don't have to do anything in particular, `QDialog` has the closing X on it by default, and connects it to `QDialog::close( )` (presumably) itself. – user4520 Oct 04 '15 at 09:11
  • Is this a fully compilable example? There's a bunch of classes here where I am not sure if they are part of Qt, like SettingsDialog (I would have expected QSettingsDialog). – Puppy Oct 04 '15 at 09:27
  • @Puppy No, these are my subclasses of Qt's classes, as described at the beginning of the question. I can provide an MCVE if necessary, I just thought this was a simple mistake on my part that could be solved without it. – user4520 Oct 04 '15 at 09:32

0 Answers0