forceActiveFocus();
// re-open input panel on press if already focused
if (hasActiveFocus() && hadActiveFocus && !isReadOnly())
- openSoftwareInputPanel();
+ qGuiApp->inputMethod()->show();
}
if (!event->isAccepted())
QQuickImplicitSizeItem::mousePressEvent(event);
}
}
-
-
-/*!
- \qmlmethod void QtQuick2::TextEdit::openSoftwareInputPanel()
-
- Opens software input panels like virtual keyboards for typing, useful for
- customizing when you want the input keyboard to be shown and hidden in
- your application.
-
- By default the opening of input panels follows the platform style. Input panels are
- always closed if no editor has active focus.
-
- You can disable the automatic behavior by setting the property \c activeFocusOnPress to false
- and use functions openSoftwareInputPanel() and closeSoftwareInputPanel() to implement
- the behavior you want.
-
- Only relevant on platforms, which provide virtual keyboards.
-
- \code
- import QtQuick 2.0
- TextEdit {
- id: textEdit
- text: "Hello world!"
- activeFocusOnPress: false
- MouseArea {
- anchors.fill: parent
- onClicked: {
- if (!textEdit.activeFocus) {
- textEdit.forceActiveFocus();
- textEdit.openSoftwareInputPanel();
- } else {
- textEdit.focus = false;
- }
- }
- onPressAndHold: textEdit.closeSoftwareInputPanel();
- }
- }
- \endcode
-*/
-void QQuickTextEdit::openSoftwareInputPanel()
-{
- if (qGuiApp)
- qGuiApp->inputMethod()->show();
-}
-
-/*!
- \qmlmethod void QtQuick2::TextEdit::closeSoftwareInputPanel()
-
- Closes a software input panel like a virtual keyboard shown on the screen, useful
- for customizing when you want the input keyboard to be shown and hidden in
- your application.
-
- By default the opening of input panels follows the platform style. Input panels are
- always closed if no editor has active focus.
-
- You can disable the automatic behavior by setting the property \c activeFocusOnPress to false
- and use functions openSoftwareInputPanel() and closeSoftwareInputPanel() to implement
- the behavior you want.
-
- Only relevant on platforms, which provide virtual keyboards.
-
- \code
- import QtQuick 2.0
- TextEdit {
- id: textEdit
- text: "Hello world!"
- activeFocusOnPress: false
- MouseArea {
- anchors.fill: parent
- onClicked: {
- if (!textEdit.activeFocus) {
- textEdit.forceActiveFocus();
- textEdit.openSoftwareInputPanel();
- } else {
- textEdit.focus = false;
- }
- }
- onPressAndHold: textEdit.closeSoftwareInputPanel();
- }
- }
- \endcode
-*/
-void QQuickTextEdit::closeSoftwareInputPanel()
-{
- if (qGuiApp)
- qGuiApp->inputMethod()->hide();
-}
-
void QQuickTextEdit::focusInEvent(QFocusEvent *event)
{
Q_D(const QQuickTextEdit);
if (d->focusOnPress && !isReadOnly())
- openSoftwareInputPanel();
+ qGuiApp->inputMethod()->show();
QQuickImplicitSizeItem::focusInEvent(event);
}
SelectWords
};
- Q_INVOKABLE void openSoftwareInputPanel();
- Q_INVOKABLE void closeSoftwareInputPanel();
-
QString text() const;
void setText(const QString &);
forceActiveFocus();
// re-open input panel on press if already focused
if (hasActiveFocus() && hadActiveFocus && !d->m_readOnly)
- openSoftwareInputPanel();
+ qGuiApp->inputMethod()->show();
}
event->setAccepted(true);
}
}
-/*!
- \qmlmethod void QtQuick2::TextInput::openSoftwareInputPanel()
-
- Opens software input panels like virtual keyboards for typing, useful for
- customizing when you want the input keyboard to be shown and hidden in
- your application.
-
- By default the opening of input panels follows the platform style. Input panels are
- always closed if no editor has active focus.
-
- You can disable the automatic behavior by setting the property \c activeFocusOnPress to false
- and use functions openSoftwareInputPanel() and closeSoftwareInputPanel() to implement
- the behavior you want.
-
- Only relevant on platforms, which provide virtual keyboards.
-
- \qml
- import QtQuick 2.0
- TextInput {
- id: textInput
- text: "Hello world!"
- activeFocusOnPress: false
- MouseArea {
- anchors.fill: parent
- onClicked: {
- if (!textInput.activeFocus) {
- textInput.forceActiveFocus()
- textInput.openSoftwareInputPanel();
- } else {
- textInput.focus = false;
- }
- }
- onPressAndHold: textInput.closeSoftwareInputPanel();
- }
- }
- \endqml
-*/
-void QQuickTextInput::openSoftwareInputPanel()
-{
- if (qGuiApp)
- qGuiApp->inputMethod()->show();
-}
-
-/*!
- \qmlmethod void QtQuick2::TextInput::closeSoftwareInputPanel()
-
- Closes a software input panel like a virtual keyboard shown on the screen, useful
- for customizing when you want the input keyboard to be shown and hidden in
- your application.
-
- By default the opening of input panels follows the platform style. Input panels are
- always closed if no editor has active focus.
-
- You can disable the automatic behavior by setting the property \c activeFocusOnPress to false
- and use functions openSoftwareInputPanel() and closeSoftwareInputPanel() to implement
- the behavior you want.
-
- Only relevant on platforms, which provide virtual keyboards.
-
- \qml
- import QtQuick 2.0
- TextInput {
- id: textInput
- text: "Hello world!"
- activeFocusOnPress: false
- MouseArea {
- anchors.fill: parent
- onClicked: {
- if (!textInput.activeFocus) {
- textInput.forceActiveFocus();
- textInput.openSoftwareInputPanel();
- } else {
- textInput.focus = false;
- }
- }
- onPressAndHold: textInput.closeSoftwareInputPanel();
- }
- }
- \endqml
-*/
-void QQuickTextInput::closeSoftwareInputPanel()
-{
- if (qGuiApp)
- qGuiApp->inputMethod()->hide();
-}
-
void QQuickTextInput::focusInEvent(QFocusEvent *event)
{
Q_D(const QQuickTextInput);
if (d->focusOnPress && !d->m_readOnly)
- openSoftwareInputPanel();
+ qGuiApp->inputMethod()->show();
QQuickImplicitSizeItem::focusInEvent(event);
}
Q_INVOKABLE void moveCursorSelection(int pos);
Q_INVOKABLE void moveCursorSelection(int pos, SelectionMode mode);
- Q_INVOKABLE void openSoftwareInputPanel();
- Q_INVOKABLE void closeSoftwareInputPanel();
-
QString text() const;
void setText(const QString &);
QTest::mouseRelease(&view, Qt::LeftButton, noModifiers, centerPoint);
QCOMPARE(qApp->inputMethod()->isVisible(), false);
- // input panel should open when openSoftwareInputPanel is called
- edit->openSoftwareInputPanel();
- QCOMPARE(qApp->inputMethod()->isVisible(), true);
-
- // input panel should close when closeSoftwareInputPanel is called
- edit->closeSoftwareInputPanel();
- QCOMPARE(qApp->inputMethod()->isVisible(), false);
-
inputMethodPrivate->testContext = 0;
}
QTest::mousePress(&view, Qt::LeftButton, noModifiers, centerPoint);
QTest::mouseRelease(&view, Qt::LeftButton, noModifiers, centerPoint);
QCOMPARE(qApp->inputMethod()->isVisible(), false);
-
- // input panel should open when openSoftwareInputPanel is called
- input->openSoftwareInputPanel();
- QCOMPARE(qApp->inputMethod()->isVisible(), true);
-
- // input panel should close when closeSoftwareInputPanel is called
- input->closeSoftwareInputPanel();
- QCOMPARE(qApp->inputMethod()->isVisible(), false);
}
class MyTextInput : public QQuickTextInput