#include <QtGui>
#include <QApplication>
{
public:
explicit Widget
(QWidget * parent
= 0) , mPushButton
(new QPushButton("Hide self and show Partner",
this)) , mPartner(0)
{ }
{
if(partner == 0)
return;
if(mPartner != partner)
{
if(mPartner != 0)
{
disconnect(mPushButton, SIGNAL(clicked()), this, SLOT(hide()));
disconnect(mPushButton, SIGNAL(clicked()), mPartner, SLOT(showMaximized()));
}
mPartner = partner;
connect(mPushButton, SIGNAL(clicked()), this, SLOT(hide()));
connect(mPushButton, SIGNAL(clicked()), mPartner, SLOT(showMaximized()));
}
}
private:
};
int main(int argc, char *argv[])
{
Widget w1;
Widget w2;
w1.setWindowTitle("Widget 1 - Look I have Changed");
w2.setWindowTitle("Widget 2 - Look I have Changed");
w1.setPartner(&w2);
w2.setPartner(&w1);
w1.showMaximized();
return app.exec();
}
#include <QtGui>
#include <QApplication>
class Widget : public QWidget
{
public:
explicit Widget(QWidget * parent = 0)
: QWidget(parent)
, mPushButton(new QPushButton("Hide self and show Partner", this))
, mPartner(0)
{ }
void setPartner(QWidget * partner)
{
if(partner == 0)
return;
if(mPartner != partner)
{
if(mPartner != 0)
{
disconnect(mPushButton, SIGNAL(clicked()), this, SLOT(hide()));
disconnect(mPushButton, SIGNAL(clicked()), mPartner, SLOT(showMaximized()));
}
mPartner = partner;
connect(mPushButton, SIGNAL(clicked()), this, SLOT(hide()));
connect(mPushButton, SIGNAL(clicked()), mPartner, SLOT(showMaximized()));
}
}
private:
QPushButton * mPushButton;
QWidget * mPartner;
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Widget w1;
Widget w2;
w1.setWindowTitle("Widget 1 - Look I have Changed");
w2.setWindowTitle("Widget 2 - Look I have Changed");
w1.setPartner(&w2);
w2.setPartner(&w1);
w1.showMaximized();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks