Qt multiscreen with Mac Spaces
-
I'm developing a Qt app in Snow Leopard now. Currently, I'm facing some strange behavior of a QDialog subclass disappearing after I switch from a different Space. It's okay if I switch Spaces through the hot keys (Control + Arrow Keys or Control + Number), but if I evoke the Spaces screen through F8 and select the Space where that app is, the dialog disappears.
Said dialog is evoked through a slot, and is assigned a parent, which is another dialog. Here's how it's evoked:
@void CDemoDlg::OnGotoFit4PointsDlg()
{
CFit4PointsDlg* pkDlg = new CFit4PointsDlg( this );
pkDlg->setModal( true );
pkDlg->exec();
delete pkDlg;
}@I even overrid the dialog's hide/move event handlers as well as the accept/reject slots to see what's going on, and it didn't appear that the dialog is hidden or moved when this happens.
Maybe this has something with how Qt works with Mac's Spaces?
I even used the QDesktopWidget to check the virtual desktop setting, and it appears that there is only one screen, even when I have 4 Spaces.
Eventually I'd like to store dialog locations for later use as well, and will need to handle cases when one dialog is in a different Space. Has anyone got any stories on having Qt working with Spaces?
-
Can you provide screenshots of
- the space with your app before switching to another space
- your spaces overview (F8 view)
- the space your dialog should reside on after the switch
Also, be aware that the application you click onto in the F8-view is brought to the foreground. It may be that you just put your dialog behind another window.
Also, is the dialog closed? In this case the exec() call should return and your program should continue. If not, the dialog is hidden somewhere.
-
There's the screenshot of how the app looks like before I switch spaces, and how it should look like after I switch back. As you can see, there is one QMainWindow with two QDialogs over it. The dialog in question is a child of another QDialog.
!http://dl.dropbox.com/u/43071740/QDialogVSSpaces/Step1.png(http://dl.dropbox.com/u/43071740/QDialogVSSpaces/Step1.png)!The Space Overview, right before I switch back from another Space:
!http://dl.dropbox.com/u/43071740/QDialogVSSpaces/Step2.png(http://dl.dropbox.com/u/43071740/QDialogVSSpaces/Step2.png)!What happens after I clicked on the app again.
!http://dl.dropbox.com/u/43071740/QDialogVSSpaces/Step3.png(http://dl.dropbox.com/u/43071740/QDialogVSSpaces/Step3.png)!Another few things. I've change the parent Dialog to display a debug message after it returns from the child dialog's exec():
@ CFit4PointsDlg* pkDlg = new CFit4PointsDlg( this, &init );
pkDlg->setModal( true );
pkDlg->exec();qDebug() << "\tReturn from Fit4PointsDlg->exec()";
delete pkDlg;@
The debug message never showed up.I even override the child dialog's event handlers and slots:
@/*******************************************************************- Reimplemented slots
*******************************************************************/
void CFit4PointsDlg::accept()
{
#ifdef _DEBUG
qDebug() << "[Fit4PointsDlg][accept] ACCEPTED";
#endif
QDialog::accept();
}
void CFit4PointsDlg::done( int r )
{
#ifdef _DEBUG
qDebug() << "[Fit4PointsDlg][done] DONE";
#endif
QDialog::done( r );
}void CFit4PointsDlg::reject()
{
#ifdef _DEBUG
qDebug() << "[Fit4PointsDlg][reject] REJECTED";
#endif
QDialog::reject();
}void CFit4PointsDlg::lower()
{
#ifdef _DEBUG
qDebug() << "[Fit4PointsDlg][lower] LOWERED";
#endif
QDialog::lower();
}void CFit4PointsDlg::setFocus()
{
#ifdef _DEBUG
qDebug() << "[Fit4PointsDlg][setFocus] Set Keyboard Focus";
#endif
QDialog::setFocus();
}/*******************************************************************
*- Reimplemented functions
*******************************************************************/
void CFit4PointsDlg::closeEvent ( QCloseEvent * e )
{
#ifdef _DEBUG
qDebug() << "[Fit4PointsDlg][closeEvent] CLOSED";
#endif
QDialog::closeEvent( e );
}void CFit4PointsDlg::hideEvent ( QHideEvent * event )
{
#ifdef _DEBUG
qDebug() << "[Fit4PointsDlg][hideEvent] HIDDEN";
#endif
QDialog::hideEvent( event );
}void CFit4PointsDlg::moveEvent( QMoveEvent * event )
{
#ifdef _DEBUG
qDebug() << "[Fit4PointsDlg][moveEvent] MOVED " << event->oldPos() << "=>" << event->pos();
#endif
QDialog::moveEvent( event );
}void CFit4PointsDlg::focusInEvent( QFocusEvent * event )
{
#ifdef _DEBUG
qDebug() << "[Fit4PointsDlg][focusInEvent] FOCUS IN " << endl
<< "\tparent: " << this->parentWidget();
#endif
QDialog::focusInEvent( event );
}void CFit4PointsDlg::focusOutEvent( QFocusEvent * event )
{
#ifdef _DEBUG
qDebug() << "[Fit4PointsDlg][focusOutEvent] FOCUS OUT " << endl
<< "\tparent: " << this->parentWidget();
#endif
QDialog::focusOutEvent( event );
}void CFit4PointsDlg::setVisible ( bool visible )
{
#ifdef _DEBUG
qDebug() << "[Fit4PointsDlg][setVisible] Set Visible " << visible;
#endif
QDialog::setVisible( visible );
}@The only functions that might responded during switching back to the Space and having the child dialog disappear is the FocusIn/Out event handlers. I was hoping somwthing will happen with hideEvent as well, but it's debug message never shows during this event.
Also, on some rare occasions, the child dialog might reappear (This is something rather erratic; I've yet to find out how to reproduce this). When it does, it will appear that the child dialog no longer has the parent dialog as a parent anymore; came to that conclusion because moving the parent dialog doesn't affect the child dialog's position anymore, as it normally does. I searched my code and was pretty sure I never explicitly reset the child dialog's parent. Maybe there's something else doing that without me knowing?
- Reimplemented slots