简体   繁体   中英

Qt - Show second Window from Mainwindow

I'm trying to show a second (Tool-)window from a Mainwindow. This should be really basic, but my solution doesn't seem to work (maybe I just can't see it?!).

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
    //...

    parametersWindow = new NoiseParamtersWindow;
    parametersWindow->show();
    parametersWindow->raise();

}

Any help is appreciated

I think the problem is that you are "showing" your tool window inside your constructor for the main window. This makes the tool window "ready" before your main window, which may confuse the windowing system because the child window is ready before the parent.

Try to show the tool window by using a zero-interval, single-shot timer . This will show the parameters window once the main window is fully initialized.

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
    //...

    parametersWindow = new NoiseParamtersWindow;
    QTimer::singleShot(0, parametersWindow. SLOT(show()));
}

i would highly advice You to do it in a show() slot or one of Your own slots. Other then that it should be a standalone window (due to You don't give it a parent) that should show, you might be encountering a bug - but i'm a little rusty with all the changes that digia made to Qt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM