Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved QMdiSubWindow creation and activation

    General and Desktop
    3
    5
    1281
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      jcga last edited by jcga

      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 ?

      K 1 Reply Last reply Reply Quote 0
      • K
        KeithS @jcga last edited by

        @jcga

        What's m_centralArea? Is it your QMdiArea?

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

        1 Reply Last reply Reply Quote 0
        • J
          jcga last edited by

          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?

          1 Reply Last reply Reply Quote 0
          • J
            jcga last edited by

            Finally it seems that simply calling

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

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

            1 Reply Last reply Reply Quote 0
            • SGaist
              SGaist Lifetime Qt Champion last edited by

              Hi,

              What about just calling setFocus on it ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply Reply Quote 0
              • First post
                Last post