PDA

View Full Version : Focus in lineEdit in QMDISubWindow



jeanrl
27th January 2011, 20:16
Hi people!

I have a problem, I need put focus in lineEdit in QMDISubWindow, but same put the command:

ui->tbConsulta->setFocus();

The Widget don't get focus.

How fix this?

Thks.

Hugs.

ChrisW67
28th January 2011, 00:05
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>

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"

jeanrl
28th January 2011, 13:41
Hi! Thks for your attentation.

This command:

QTimer::singleShot(5000, edit2, SLOT(setFocus()));

Worked, but I think that this is a palliative, at least to me, but resolved my problem.

Thks another time.

Hugs.

ChrisW67
30th January 2011, 23:07
The single shot timer was only there to provide something to change the focus in the example and demonstrate that focus does move. It doesn't fix any problem.