PDA

View Full Version : move parent window to the front.



hvengel
1st February 2007, 00:01
I have the following problem I am trying to solve:

My main window contains an image. In a child dialog that is opened from the main window the user needs to be able to go to the main window and select an area from the image then return control to the child dialog. This is optional and should only happen if the user clicks a button on the child dialog.

I have setup a signal in the child dialog and a slot in the main window to handle the interaction. But I can't get the main window to come to the front. I have tried using raise() in the main window and also stackUnder(parentWidget (FALSE)) (parentWidget (FALSE) always returns 0 so it is not working) in the child dialog to bring the main window forward. The main window clearly ends up with the focus when the button in the child dialog is clicked but only because I pop up a QMessageBox in the slot that handles the signal emitted by the child dialog but the main window is stuck behind the child dialog. The child dialog is modeless.

I am using QT3 if that matters.

aamer4yu
1st February 2007, 04:03
did u try activateWindow() ??

hvengel
2nd February 2007, 05:07
I can't figure out how to use activateWindow() in QT 3 for this. This is not a member of the QDialog class which is what my windows are. In fact in QT 3 it appears that activateWindow() is part of the QWorkspace class. QWorkspace appears to be for doing MDI stuff. My app is not an MDI app and I have no objects that are of QWorkspace class. So I was not even able to figure out how to get this to build when I call activateWindow(). In QT 4 it appears that activateWindow() is part of the QDialog class.

I have figured out that this is a modality issue that had to do with the way I was instantiating the child dialog. What I was doing was creating the child dialog if a certain button was pushed on the main window and then destroying the dialog when returning control to the main window. What I have learned is that when a dialog is created this way there is no way to make it modeless (IE. it is always modal). What I ended up doing was to instantiate the child dialog during the application startup like this:


int main( int argc, char **argv )
{
QApplication a( argc, argv );

// create child dialog
ProfileParms profParms;
profParms.setModal(FALSE);
profParms.show();
// hide dialog until needed
profParms.hide();

// create main window
lprofMain w;
w.show();

// Setup signals and slots connections so that
// main window and child dialog can interact as needed
QObject::connect(&profParms, SIGNAL(signalPickRGB()), &w, SLOT(slotPickRGBPatch()));
QObject::connect(&profParms, SIGNAL(profileParmsOK()), &w, SLOT(slotUpdateProfileParmsText()));
QObject::connect(&w, SIGNAL(showProfileParms()), &profParms, SLOT(slotShow()));


a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );

// Start everything running
return a.exec();
}

It took me a while to figure this out but it is working.

aamer4yu
2nd February 2007, 05:26
good u solved the problem

activateWindow is a function of QWidget in Qt 4.2.0 onwards. I am not sure about Qt 3

davit
2nd February 2007, 08:41
Hi,

You can use setActiveWindow() in Qt3

Davit