PDA

View Full Version : MainWindow in front of child modeless dialog



jiveaxe
10th August 2007, 14:49
Hi,
i have a problem managing mainwindow and dialogs; I have created a mainwindow and clicking on a button it opens a modeless dialog: here the calling function:


void MainWindow::viewArticle(const QModelIndex& current)
{
if(!articleViewer)
{
articleViewer = new ArticleViewer(this);
}
if articleViewer {
articleViewer->show();
} else {
articleViewer->activateWindow();
}
}

even if i can interact with mainWindow it is always behind the child dialog, which occupy a great part of the screen; should be better choosing at any time what window take in front (like in Qt Designer 4).

Any suggestions?

Thanks

marcel
10th August 2007, 15:12
Don't create the dialog with a parent( don't pass "this" as parameter, pass NULL).
The downside is you will get a taskbar button for the dialog.

Regards

jiveaxe
10th August 2007, 16:08
Thank you marcel, now is working and never mind for the new entry in the taskbar.

One more stupid question; when i close the mainwindow the child remains open. I have created a destructor for the mainWindow like this:


MainWindow::~MainWindow()
{
if(gameViewer)
gameViewer->close();
}

but doesn't work.

Regards

marcel
10th August 2007, 16:13
Probably it does not enter the destructor yet.
Either use setAttribute(Qt::WA_DeleteOnClose) in the constructor of the main window.

Or:
Override the main window's close event, and do that there.


MainWindow::closeEvent(QCloseEvent*)
{
if(gameViewer)
{
gameViewer->close();
delete gameViewer; //you also have to delete it manually, since it does not have a parent
}
}


Regards

jiveaxe
10th August 2007, 16:18
The override solution works good.

Grazie mille