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. AddSubWindow

AddSubWindow

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 4.4k 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.
  • I Offline
    I Offline
    itzram
    wrote on last edited by
    #1

    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
    0
    • L Offline
      L Offline
      laumaya
      wrote on last edited by
      #2

      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
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

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

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

          1 Reply Last reply
          0
          • I Offline
            I Offline
            itzram
            wrote on last edited by
            #5

            Thanks laumaya.

            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