Results 1 to 6 of 6

Thread: How I can add subwindows to QMdiArea by Clicking a QPushButton

  1. #1
    Join Date
    Jun 2010
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default How I can add subwindows to QMdiArea by Clicking a QPushButton

    Hi to all!!


    How I can add subwindows to a QMdiArea by clicking a QPushButton

    Any help will be appreciated!!!!

    Thanks.

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    503
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How I can add subwindows to QMdiArea by Clicking a QPushButton

    Hi, make a slot, connect pushbutton's clicked() signal to it and call addSubWindow().

    Ginsengelf

  3. #3
    Join Date
    Jun 2010
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How I can add subwindows to QMdiArea by Clicking a QPushButton

    Thanks!

    ReqFormDet *MainWindow::sLoadReqFormDet()
    {
    ReqFormDet *reqfd = new ReqFormDet;
    ui->mdiArea->addSubWindow(reqfd);
    ui->mdiArea->DontMaximizeSubWindowOnActivation;
    reqfd->show();
    reqfd->activateWindow();
    return reqfd;
    }

    void SearchForm:nDoubleClickOpen()
    {
    MainWindow *w = new MainWindow;
    w->sLoadReqFormDet();
    }

    connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(onDoubleClickOpen()));

    this is my code but it does not show the windows on mdiArea. It only work by clicking on QAction Button on main toolbar

    Could you show me how to do it through a example?

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How I can add subwindows to QMdiArea by Clicking a QPushButton

    The code snippet you posted won't compile so it is not clear you have a running program. You should post code that compiles and use code tags. You need to think about what should happen and where: do you really want to create a new main window every time you click the button?

    Qt Code:
    1. #include <QtCore>
    2. #include <QtGui>
    3.  
    4. class SubWindowWidget: public QLabel {
    5. public:
    6. SubWindowWidget() {
    7. setText("I'm a sub-window");
    8. }
    9. };
    10.  
    11. class MainWindow: public QMainWindow {
    12. Q_OBJECT
    13.  
    14. public:
    15. MainWindow() {
    16. QWidget *w = new QWidget(this);
    17. QPushButton *p = new QPushButton("New Sub-window", this);
    18. mdi = new QMdiArea(this);
    19.  
    20. QVBoxLayout *l = new QVBoxLayout(w);
    21. l->addWidget(p);
    22. l->addWidget(mdi);
    23. w->setLayout(l);
    24. setCentralWidget(w);
    25.  
    26. connect(p, SIGNAL(clicked()), this, SLOT(addSubWin()));
    27. }
    28. private:
    29. QMdiArea *mdi;
    30.  
    31. private slots:
    32. void addSubWin() {
    33. SubWindowWidget *sw = new SubWindowWidget;
    34. mdi->addSubWindow(sw);
    35. sw->show();
    36. }
    37. };
    38.  
    39. int main(int argc, char **argv)
    40. {
    41. QApplication app(argc, argv);
    42.  
    43. MainWindow mw;
    44. mw.show();
    45. app.exec();
    46. }
    47. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to ChrisW67 for this useful post:

    mrondon (15th June 2010)

  6. #5
    Join Date
    Jun 2010
    Location
    India
    Posts
    50
    Thanks
    1
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How I can add subwindows to QMdiArea by Clicking a QPushButton

    This should fix your problem.


    Qt Code:
    1. QMdiSubWindow* pSubWindow=ui->mdiArea->addSubWindow(reqfd);
    2. if(pSubWindow)
    3. pSubWindow->show();
    To copy to clipboard, switch view to plain text mode 

    Note: ReqFormDet *reqfd = new ReqFormDet; is set as internal widget of QMdiSubWindow when you call mdiArea->addSubWindow(reqfd);

  7. The following 2 users say thank you to agathiyaa for this useful post:

    massood (16th February 2013), mrondon (15th June 2010)

  8. #6
    Join Date
    Jun 2010
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How I can add subwindows to QMdiArea by Clicking a QPushButton

    Thanks great samples!!

Similar Threads

  1. display order of subwindows in mdi area
    By eric_vi in forum Qt Programming
    Replies: 3
    Last Post: 11th May 2010, 17:05
  2. Replies: 0
    Last Post: 22nd February 2010, 10:30
  3. QMainWindow...button in subwindows
    By Peppy in forum Qt Programming
    Replies: 1
    Last Post: 15th October 2009, 16:52
  4. Update menu items on switching MDI subwindows
    By John_P in forum Qt Programming
    Replies: 1
    Last Post: 16th March 2008, 00:48
  5. Replies: 3
    Last Post: 26th September 2006, 13:16

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.