MdiArea first window not being selected
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
Re: MdiArea first window not being selected
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?
Re: MdiArea first window not being selected
Hi
Here is the code which creates the children.
Code:
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
Re: MdiArea first window not being selected
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.
Re: MdiArea first window not being selected
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.
Code:
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;
}
Re: MdiArea first window not being selected
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
Re: MdiArea first window not being selected
Excellent.
On closer reading it seems my Qt::WA_DeleteOnClose comment only applies to the QMdiSubWindow and not its contents anyway.