Results 1 to 8 of 8

Thread: Show parent window

  1. #1
    Join Date
    Mar 2009
    Posts
    116
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Show parent window

    Hello All,


    I have developed one application,in which I m using 4-5 different screens to navigate.

    Now from Mainwindow screen I have activated the another screen,so my mainwindow is now hidden .But in this new screen on one button click event I need to show the mainwindow screen .

    How to acheive it???

    The code I m using is as follows

    in MainWindow.cpp

    Qt Code:
    1. void MainWindow::f_Open_screen_al()
    2. {
    3. screen_al->show();
    4. screen_al->activateWindow();
    5. }
    6.  
    7. void MainWindow::ShowMainWindow()
    8. {
    9. this->activateWindow();
    10. }
    To copy to clipboard, switch view to plain text mode 

    and in screen_al.cpp
    Qt Code:
    1. connect(ui.pushbutton, SIGNAL(clicked()), this->parent(), SLOT(ShowMainWindow()));
    To copy to clipboard, switch view to plain text mode 

    But No mainwindow is displayed.....

    Pls help

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Show parent window

    try this
    Qt Code:
    1. void MainWindow::ShowMainWindow()
    2. {
    3. raise();
    4. this->activateWindow();
    5. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Mar 2009
    Posts
    116
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Show parent window

    I tried this code

    Qt Code:
    1. void MainWindow::ShowMainWindow()
    2. {
    3. QMessageBox::information(this,"ShowMainWindow","ShowMainWindow");
    4. raise();
    5. this->activateWindow();
    6. }
    To copy to clipboard, switch view to plain text mode 

    The QMessageBox is displayed but no child window is closed nor the mainwindow is displayed

    For activating the mainWindow I used the code

    Qt Code:
    1. ui.setupUi(this);
    To copy to clipboard, switch view to plain text mode 

    and in ui_mainwindow.h "this" is QMainWindow type

    Qt Code:
    1. void setupUi(QMainWindow *MainWindow)
    To copy to clipboard, switch view to plain text mode 

    what to do now?

  4. #4
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Show parent window

    you said that your main window was hidden? if u called hide() then you should call show() in MainWindow::ShowMainWindow()

    try it

    Qt Code:
    1. void MainWindow::ShowMainWindow()
    2. {
    3. show();
    4. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Mar 2009
    Posts
    116
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Show parent window

    I want to call one of my mainwindow function on close event of child window ,how to connect this signal..


    Previously I tried
    Qt Code:
    1. connect(this,SIGNAL(destroyed()),this->parent(),SLOT(f_max()));
    To copy to clipboard, switch view to plain text mode 

    but as I m closing a child window using
    Qt Code:
    1. this->close()
    To copy to clipboard, switch view to plain text mode 

    so "destroyed event "is not getting triggered ...

  6. #6
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Show parent window

    try these

    Qt Code:
    1. this->close();
    2. MyMainWindow*p=(MyMainWindow*)this->parent();
    3. p->f_max();
    To copy to clipboard, switch view to plain text mode 

    or

    Qt Code:
    1. void child::closeEvent(QCloseEvent*)
    2. {
    3.  
    4. MyMainWindow*p=(MyMainWindow*)this->parent();
    5. p->f_max();
    6.  
    7. }
    To copy to clipboard, switch view to plain text mode 

    or

    Qt Code:
    1. MyMainWindow*p=(MyMainWindow*)this->parent();
    2. connect(this,SIGNAL(destroyed()),p,SLOT(f_max()));
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Mar 2009
    Posts
    116
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Show parent window

    Qt Code:
    1. MyMainWindow*p=(MyMainWindow*)this->parent();
    To copy to clipboard, switch view to plain text mode 

    In above code ,In place of "MyMainWindow" what should I put?

    in mainwindow .h class is decraled as..

    Qt Code:
    1. class MainWindow : public QMainWindow
    2. {
    3. }
    To copy to clipboard, switch view to plain text mode 


    cant we connect a close event to parent window function???

    I just need to detect the close event of this child window and connect my f_max() function to that signal

  8. #8
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Show parent window

    put MainWindow instead of MyMainWindow and use the closeEvent code i showed u

Similar Threads

  1. Parent window over child
    By neolol in forum Qt Programming
    Replies: 4
    Last Post: 15th May 2009, 21:15
  2. connecting child to parent window...
    By sumit in forum Qt Programming
    Replies: 1
    Last Post: 19th October 2008, 21:28
  3. How to close parent window from child window?
    By montylee in forum Qt Programming
    Replies: 5
    Last Post: 14th October 2008, 11:40
  4. Getting a parent window from a QT/Linux library
    By nicolas44 in forum Qt Programming
    Replies: 8
    Last Post: 31st May 2007, 08:17
  5. move parent window to the front.
    By hvengel in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2007, 08:41

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.