Details
-
Bug
-
Resolution: Done
-
P2: Important
-
4.7.0
-
None
-
1c21463
Description
With default configuration, input items do not get focus / do not work within a QmlView.
Say you create a minimal qml example:
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { QDeclarativeView *view = new QDeclarativeView; view->setSource(QUrl("test.qml")); setCentralWidget(view); }
With test.qml being defined as:
import Qt 4.6
TextInput{
width: 200
height: 200
}
If you launch this, you can click on the Input, and get a blinking cursor, but you can't type. For this you have to change the focusPolicy:
view->setFocusPolicy(Qt::ClickFocus);
This is because QmlView calls
viewport()->setFocusPolicy(Qt::NoFocus)
which doesn't seem right. Also the qml viewer does this:
"canvas->setFocus();"
which can probably be better achieved by setFocusPolicy(Qt::StrongFocus).
(Sometimes you also have to explicitly activate the scene afterwards, e.g. following line is also needed in Bauhaus):
QApplication::sendEvent(myQmlView->scene(), new QEvent(QEvent::WindowActivate));