QMdiSubWindow creation and activation



  • Hello,

    I have written an QMdi application with the MainWindow generated by QtCreator. In the constructor of MainWindow, I create QMdiSubwindows via a specific function (UString is just a class derived from wstring, not important here)

    QMdiSubWindow* MainWindow::createSubWindow(UString& name)
    {
        m_subwndcnt++;
        if( name=="_AUTO_") name.format(L"Plot %d",m_subwndcnt);
    
        QSplitter* splitter=new QSplitter();
        QMdiSubWindow* subwin=m_centralArea->addSubWindow(splitter);
        subwin->setWindowTitle(name.toQString());
    
         subwin->show();
    
        return subwin;
    
    }
    

    I can also add sub windows via a Menu entry that calls a specific slot on MainWindow class from where I simply call the above function.

    Now I observe a strange behavior: If I create a sub window -- say "Plot 1" -- (via the above function) inside the constructor of MainWindow, and the add via the menu entry another sub window -- say Plot 2 --, then I cannot change the widow which is activated, that is, I can click on either of the two sub windows, Plot 1 or Plot 2 and the activation mark (the dark frame of the subwindow) does not change. If i test by calling m_centralArea->activeWindow() it is always Plot 1 which is activated.
    But if in the constructor of MainWindow I create two sub windows (Plot 1 and Plot 2), subwindow activation by clicking works perfectly, and if after that I create via the menu entry a thrid subwindow Plot 3 I can activate it by clicking on it, but m_centralArea->setActiveSubWindow(pointer to 'Plot 3') does not work! In fact, it seems that a subWindow created outside the constructor of MainWindow cannot be activated programmatically.

    Someone has a hint for what is happening ?



  • @jcga

    What's m_centralArea? Is it your QMdiArea?

    What's splitter? Is it a QMdiSubWindow* created via new?



  • QMdiArea* m_centralArea is a property of MainWindow, created as

    m_centralArea=new QMdiArea(this);
    

    splitter is an object of Qt class QSplitter, which is derived from QFrame.
    QSplitter* splitter=new QSplitter(this);

    It is perhaps a problem that it is not derived from QMidSubWindow?



  • Finally it seems that simply calling

    subwin->hide()
    subwin->show()
    

    after having created and displayed the sub window once activates it.


  • Lifetime Qt Champion

    Hi,

    What about just calling setFocus on it ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.