Results 1 to 7 of 7

Thread: How to Close SubWindow in MdiArea

  1. #1
    Join Date
    Jun 2012
    Posts
    41
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default How to Close SubWindow in MdiArea

    Hi everyone.
    I need a little help.

    I am developing an application using MdiArea and can not close another
    form through its close button (PushButton).

    Can someone show me where I am going wrong, follows code below.

    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include "formwidget.h" [COLOR="#FF0000"]-----------> Include of SubWindow[/COLOR]
    6.  
    7. namespace Ui {
    8. class MainWindow;
    9. }
    10.  
    11. class MainWindow : public QMainWindow
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. explicit MainWindow(QWidget *parent = 0);
    17. ~MainWindow();
    18.  
    19. private slots:
    20. void on_actionClients_triggered();
    21.  
    22. private:
    23. Ui::MainWindow *ui;
    24. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. MainWindow::MainWindow(QWidget *parent) :
    5. QMainWindow(parent),
    6. ui(new Ui::MainWindow)
    7. {
    8. ui->setupUi(this);
    9. setCentralWidget(ui->mdiArea); [COLOR="#FF0000"]---------> Centering MdiArea[/COLOR]
    10.  
    11. }
    12.  
    13. MainWindow::~MainWindow()
    14. {
    15. delete ui;
    16. }
    17.  
    18. void MainWindow::on_actionClients_triggered()
    19. {
    20. FormWidget *frmClients = new FormWidget;
    21. ui->mdiArea->addSubWindow(frmClients);
    22. frmClients->show(); [COLOR="#FF0000"]-----------------------------> Instantiating the subwindow[/COLOR]
    23. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "formwidget.h"
    2. #include "ui_formwidget.h"
    3.  
    4. FormWidget::FormWidget(QWidget *parent) :
    5. QWidget(parent),
    6. ui(new Ui::FormWidget)
    7. {
    8. ui->setupUi(this);
    9. }
    10.  
    11. FormWidget::~FormWidget()
    12. {
    13. delete ui;
    14. }
    15.  
    16. void FormWidget::on_pushButton_clicked()
    17. {
    18. close(); --------> [COLOR="#FF0000"]Does not work, the widget disappears (LineEdit, Label, Pushbutton) and the form does not close.[/COLOR]
    19. }
    To copy to clipboard, switch view to plain text mode 

    I thank the help.

    João Marcos .
    Attached Images Attached Images
    Last edited by anda_skoa; 29th June 2016 at 08:49. Reason: missing [code] tags

  2. #2
    Join Date
    Jun 2012
    Posts
    41
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to Close SubWindow in MdiArea

    Someone who can help.

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to Close SubWindow in MdiArea

    You are calling close on the content of the sub window, not on the sub window itself.

    Cheers,
    _

  4. #4
    Join Date
    Jun 2012
    Posts
    41
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to Close SubWindow in MdiArea

    Regards, Anda_Skoa.

    Thanks for helping me.
    You have an example of how would this code.
    For the lock button is in the form and the form within the MdiArea.

    PS: Thank you to format my post.

    Regards,

    João Marcos

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to Close SubWindow in MdiArea

    You could emit a signal from the FormWidget and connect that to the sub window's close slot.

    Or could check if the sub window is the FormWidget's parent or grand parent and call close directly.

    Cheers,
    _

  6. #6
    Join Date
    Jun 2012
    Posts
    41
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to Close SubWindow in MdiArea

    Hi, Anda_Skoa.

    Following its first orientation, I created a button sign for the form (Close slot) and did not work. I used QtCreator for this.

    I searched for any subroutine or function and bumped into "this-> parentWidget () -> close ();" it worked !!! .

    I think that fits in its second orientation.

    I appreciate your help enough, and I hope this information will help other developers.

    PS: How to check if the Sub Window is the parent or grand FormWidget's?

    Cheers,

    João Marcos

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to Close SubWindow in MdiArea

    Quote Originally Posted by marcos.miranda View Post
    Following its first orientation, I created a button sign for the form (Close slot) and did not work.
    What did not work?
    Did you connect the button's signal to your signal or did you emit your signal from the existing slot?
    Did you connect your signal to the mdi sub window's slot?

    Quote Originally Posted by marcos.miranda View Post
    I searched for any subroutine or function and bumped into "this-> parentWidget () -> close ();" it worked !!! .
    As I expected.

    Quote Originally Posted by marcos.miranda View Post
    PS: How to check if the Sub Window is the parent or grand FormWidget's?
    By casting the parent to the class you want to check for using a cast that checks if it is possible, e.g. qobject_cast

    Qt Code:
    1. QMdiSubWindow *window = qobject_cast<QMdiSubWindow*>(parentWidget());
    2. if (window != 0) // -> parent is the sub window
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

Similar Threads

  1. Replies: 0
    Last Post: 6th August 2015, 09:34
  2. Replies: 4
    Last Post: 15th October 2012, 14:00
  3. MdiArea first window not being selected
    By parsnips146 in forum Newbie
    Replies: 6
    Last Post: 23rd August 2010, 23:38
  4. simple mdiArea example wanted ..
    By AbuYusuf in forum Qt Programming
    Replies: 1
    Last Post: 11th February 2010, 22:54
  5. positioning sub windows in an mdiarea
    By eric_vi in forum Qt Programming
    Replies: 2
    Last Post: 20th August 2009, 23:08

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.