Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QMdiSubWindow creation and activation
Qt 6.11 is out! See what's new in the release blog

QMdiSubWindow creation and activation

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.8k Views 1 Watching
  • 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 Offline
    J Offline
    jcga
    wrote on last edited by jcga
    #1

    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
    0
    • J 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 Offline
      K Offline
      KeithS
      wrote on last edited by
      #2

      @jcga

      What's m_centralArea? Is it your QMdiArea?

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

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jcga
        wrote on last edited by
        #3

        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
        0
        • J Offline
          J Offline
          jcga
          wrote on last edited by
          #4

          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
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            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
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved