Results 1 to 5 of 5

Thread: MainWindow in front of child modeless dialog

  1. #1
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default MainWindow in front of child modeless dialog

    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:

    Qt Code:
    1. void MainWindow::viewArticle(const QModelIndex& current)
    2. {
    3. if(!articleViewer)
    4. {
    5. articleViewer = new ArticleViewer(this);
    6. }
    7. if articleViewer {
    8. articleViewer->show();
    9. } else {
    10. articleViewer->activateWindow();
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

    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
    Last edited by jiveaxe; 10th August 2007 at 15:09.
    Giuseppe CalÃ

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MainWindow in front of child modeless dialog

    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

  3. #3
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: MainWindow in front of child modeless dialog

    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:

    Qt Code:
    1. MainWindow::~MainWindow()
    2. {
    3. if(gameViewer)
    4. gameViewer->close();
    5. }
    To copy to clipboard, switch view to plain text mode 

    but doesn't work.

    Regards
    Giuseppe CalÃ

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MainWindow in front of child modeless dialog

    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.
    Qt Code:
    1. MainWindow::closeEvent(QCloseEvent*)
    2. {
    3. if(gameViewer)
    4. {
    5. gameViewer->close();
    6. delete gameViewer; //you also have to delete it manually, since it does not have a parent
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

    Regards

  5. The following user says thank you to marcel for this useful post:

    jiveaxe (10th August 2007)

  6. #5
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: MainWindow in front of child modeless dialog

    The override solution works good.

    Grazie mille
    Giuseppe CalÃ

Similar Threads

  1. Communication between MainWindow and a dialog
    By Backslash in forum Newbie
    Replies: 9
    Last Post: 3rd August 2007, 04:27
  2. move parent window to the front.
    By hvengel in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2007, 08:41
  3. Replies: 3
    Last Post: 23rd July 2006, 18:02

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.