I don't know about chaning focus wysota mentioned, but changeEvent works perfectly fine on w7 an ubuntu for me:
// main
int main(int argc, char *argv[])
{
MainWindow w;
w.show();
MainWindow w2;
w2.show();
return a.exec();
}
// main
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
MainWindow w2;
w2.show();
QObject::connect( &w, SIGNAL( activated( QWidget* ) ), &w2, SLOT( activate( QWidget* ) ) );
QObject::connect( &w2, SIGNAL( activated( QWidget* ) ), &w, SLOT( activate( QWidget* ) ) );
return a.exec();
}
To copy to clipboard, switch view to plain text mode
// mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui/QMainWindow>
{
Q_OBJECT
public:
protected:
void changeEvent
( QEvent* e
);
public slots:
signals:
};
#endif // MAINWINDOW_H
// mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui/QMainWindow>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow( QWidget* parent = 0 );
protected:
void changeEvent( QEvent* e );
public slots:
void activate( QWidget* w );
signals:
void activated( QWidget* w );
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
// mainwindow.cpp
#include "mainwindow.h"
#include <QEvent>
MainWindow
::MainWindow( QWidget* p
) :
{
}
void MainWindow
::changeEvent( QEvent* e
) {
if( e
->type
() == QEvent::ActivationChange && this->isActiveWindow() )
{
emit this->activated( this );
}
}
void MainWindow
::activate( QWidget* w
) {
this->raise();
this->stackUnder( w );
}
// mainwindow.cpp
#include "mainwindow.h"
#include <QEvent>
MainWindow::MainWindow( QWidget* p )
:
QMainWindow( p )
{
}
void MainWindow::changeEvent( QEvent* e )
{
if( e->type() == QEvent::ActivationChange
&& this->isActiveWindow() )
{
emit this->activated( this );
}
QMainWindow::changeEvent( e );
}
void MainWindow::activate( QWidget* w )
{
this->raise();
this->stackUnder( w );
}
To copy to clipboard, switch view to plain text mode
Bookmarks