1 Attachment(s)
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.
Code:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "formwidget.h" [COLOR="#FF0000"]-----------> Include of SubWindow[/COLOR]
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
private slots:
void on_actionClients_triggered();
private:
Ui::MainWindow *ui;
};
Code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
setCentralWidget(ui->mdiArea); [COLOR="#FF0000"]---------> Centering MdiArea[/COLOR]
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_actionClients_triggered()
{
FormWidget *frmClients = new FormWidget;
ui->mdiArea->addSubWindow(frmClients);
frmClients->show(); [COLOR="#FF0000"]-----------------------------> Instantiating the subwindow[/COLOR]
}
Code:
#include "formwidget.h"
#include "ui_formwidget.h"
FormWidget
::FormWidget(QWidget *parent
) : ui(new Ui::FormWidget)
{
ui->setupUi(this);
}
FormWidget::~FormWidget()
{
delete ui;
}
void FormWidget::on_pushButton_clicked()
{
close(); --------> [COLOR="#FF0000"]Does not work, the widget disappears (LineEdit, Label, Pushbutton) and the form does not close.[/COLOR]
}
I thank the help.
João Marcos .
Re: How to Close SubWindow in MdiArea
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,
_
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
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,
_
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 !!! :D.
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
Re: How to Close SubWindow in MdiArea
Quote:
Originally Posted by
marcos.miranda
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
I searched for any subroutine or function and bumped into "this-> parentWidget () -> close ();" it worked !!! :D.
As I expected.
Quote:
Originally Posted by
marcos.miranda
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
Code:
QMdiSubWindow *window = qobject_cast<QMdiSubWindow*>(parentWidget());
if (window != 0) // -> parent is the sub window
Cheers,
_