Qt Forum

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

    AddSubWindow

    General and Desktop
    3
    5
    3887
    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.
    • I
      itzram last edited by

      I have an application whose centralWidget is a QMdiArea and I am trying to add a new subwindow to the QMdiArea whenever someone clicks a button. The sample code I used to implement it is shown below. I see that the addSubWindow call adds new subwindows when I call it from the constructor of the MainWindow class but fails to show a new subwindow when I call it from the openNewTab slot. I am sure(using print statements) that addSubWindow method is called from openNewTab slot. I read the docs multiple times and it looks like this should work, but it doesn't. I am definitely doing missing something. Any pointers?

      I am using latest Qt on a Macbook pro.

      @
      class MyMdiArea : public QMdiArea {

      slot:
      void addSubWindow() {
      widget = new QWidget();
      addSubWindow(widget);
      }
      }

      class MainWindow : public QMainWindow
      {
      MainWindow::MainWindow()
      {
      myMdiArea = new MyMdiArea(this);
      myMdiArea->addSubWindow(); //works
      myMdiArea->addSubWindow(); //works

         QToolBar *toolBar = addToolBar(tr("Navigation"));                                                
         QAction* newTabAction = new QAction(tr("&New Tab"), this);                                       
         newTabAction->setStatusTip(tr("Open a new Tab in this workspace"));                              
         toolBar->addAction(newTabAction);                                                                                                                                    
         connect(newTabAction, SIGNAL(triggered()), SLOT(openNewTab()));                                  
                                                                                                       
         toolBar->addWidget(locationEdit);                                                                
                                                                                                       
         setCentralWidget(mdiArea);                                                                       
         setUnifiedTitleAndToolBarOnMac(true);                                                            
      }
      

      //slot
      void OpenNewTab() {
      myMdiArea->addSubWindow(); // doesn't work
      }
      }
      @

      1 Reply Last reply Reply Quote 0
      • L
        laumaya last edited by

        Hello,
        By default subWindow are hidden. Don't know why !
        So the modification is easy :
        @ //slot
        void OpenNewTab() {
        QMdiSubWindow * pSubWindow= myMdiArea->addSubWindow();
        pSubWindow->show();
        }@

        1 Reply Last reply Reply Quote 0
        • A
          andre last edited by

          All widgets that you create need to be shown at some point. For your main window, you usually do that in your main() function. All child widgets automatically also get shown at that point. But for widgets you create later on in the life of the program, you need to do that explicitly.

          1 Reply Last reply Reply Quote 0
          • L
            laumaya last edited by

            Thanks, I think that it's for performance purpose.

            1 Reply Last reply Reply Quote 0
            • I
              itzram last edited by

              Thanks laumaya.

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