Is the sub window containing the widget the active MDI sub window or not? The focus only visibly changes in the active sub window although it has changed in the other sub-windows too. Does this help?
#include <QtGui>
{
Q_OBJECT
public:
layout->addWidget(edit1);
layout->addWidget(edit2);
setLayout(layout);
edit1->setFocus();
QTimer::singleShot(5000, edit2,
SLOT(setFocus
()));
// switch focus in 5 seconds }
private:
};
int main(int argc, char *argv[])
{
QMdiArea m;
m.addSubWindow(new MyWidget);
m.addSubWindow(new MyWidget);
m.show();
return app.exec();
}
#include "main.moc"
#include <QtGui>
class MyWidget: public QWidget
{
Q_OBJECT
public:
MyWidget(QWidget *p = 0): QWidget(p) {
edit1 = new QLineEdit(this);
edit2 = new QLineEdit(this);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(edit1);
layout->addWidget(edit2);
setLayout(layout);
edit1->setFocus();
QTimer::singleShot(5000, edit2, SLOT(setFocus())); // switch focus in 5 seconds
}
private:
QLineEdit *edit1;
QLineEdit *edit2;
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QMdiArea m;
m.addSubWindow(new MyWidget);
m.addSubWindow(new MyWidget);
m.show();
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks