PDA

View Full Version : MdiArea first window not being selected



parsnips146
20th August 2010, 16:52
Hi

I have a program using a mdi area and each document is shown in this, it works fine and loads the subwidget fine. The program opens the files which were open last time it was run on start up.
The issue is if it is only opening one file it manages to do so but seems unable to set it to be the active MDI subwindow so i cannot close it or save it. is there anything that has to be done specially for it to be active. Please note that if it has to open two subwindows then it all works fine and if it opens none on start up and then i create just 1 new one then it works fine aswell.

Thanks

James

ChrisW67
23rd August 2010, 02:16
No, nothing. If there is only one child it is the active child on all my MDI apps under Linux/Windows. How are you adding these sub-windows to the MDI area?

parsnips146
23rd August 2010, 08:47
Hi

Here is the code which creates the children.



bool MainWindow::LoadRecentFiles()
{
if(!recentFiles.empty())
{
for (int x = 0; x < (recentFiles.size()); ++x)
{
ceguSubWidget *child = new ceguSubWidget();
mdiArea->addSubWindow(child);
if (child->load(recentFiles.at(x)))
child->show();
else
child->close();
}
return true;
}
else
return false;
}

Thanks

ChrisW67
23rd August 2010, 09:14
Some observations and questions.

Do you want to capture the return value from addSubWindow and use show() and close() against that?
Perhaps only add the sub window if the child successfully opens the recent file (but be careful to delete if it fails).
Your method can return true even if none of the recent files could be opened.
Does your ceguSubWidget class set Qt::WA_DeleteOnClose (see the QMdiArea::addSubWindow() docs)? This affects focus behaviour of the remaining windows when close() is called.

parsnips146
23rd August 2010, 09:35
The ceguSub Wiget does have the deleteonclose option set when it is created.

I have modified the creation code but it still has the same problems.


bool MainWindow::LoadRecentFiles()
{

if(!recentFiles.empty())
{
for (int x = 0; x < (recentFiles.size()); ++x)
{
ceguSubWidget *child = new ceguSubWidget();
if (mdiArea->addSubWindow(child))
{
if (child->load(recentFiles.at(x)))
{
child->show();
return true;
}
else
{
child->close();
return false;
}
}
}
}

return false;
}

parsnips146
23rd August 2010, 09:50
I have found the issue it was that load RecentFiles was called before the mainwindow had been set to show.

thanks for your help

James

ChrisW67
23rd August 2010, 23:38
Excellent.

On closer reading it seems my Qt::WA_DeleteOnClose comment only applies to the QMdiSubWindow and not its contents anyway.