qt virtual keyboard and non-modal dialog - qt

Is it possible to make Qt Quick application to continue input, while TextField is in the non-modal Dialog, which parented to some of children of an ApplicationWindow and InputPanel is a footer of the window?
Currently on desktop (Ubuntu 16.04 w/ GNOME) Dialog is QDialog widget-based. And when I touch virtual keyboard the Dialog lost focus and virtual keyboard became inactive because of enabled property defined as follows:
footer: InputPanel {
enabled: Qt.inputMethod.visible
}
It is a circulus vituosus. Either I need a latest fallback from cite (the cite if for FileDialog, but it may still be actual for Dialog):
The implementation of FileDialog will be a platform file dialog if possible. If that isn't possible, then it will try to instantiate a QFileDialog. If that also isn't possible, then it will fall back to a QML implementation, DefaultFileDialog.qml. In that case you can customize the appearance by editing this file. DefaultFileDialog.qml contains a Rectangle to hold the dialog's contents, because certain embedded systems do not support multiple top-level windows. When the dialog becomes visible, it will automatically be wrapped in a Window if possible, or simply reparented on top of the main window if there can only be one window.
Or I need a way to touch virtual keyboard, but not lost focus from a Qt Quick Control.

Related

What Object has Active Focus in QML?

i have a complex GUI with QML but in some situation i lost my focus and i don't know what object has active focus.
Is there any tools or ways to search in QML files and find focused Object?
I use this line to see which item has active focus:
Window {
onActiveFocusItemChanged: print("activeFocusItem", activeFocusItem)
}
This code responds to changes in the activeFocusItem property of Window by printing out the item with active focus. ApplicationWindow from Qt Quick Controls 1 and 2 have the same property since they derive from Window.
To find out how an item got focus, you can set the QT_LOGGING_RULES environment variable to qt.quick.focus = true. This enables logging for Qt's internal focus handling. The output can be a bit tricky to follow though..
Since you're using Qt Quick Controls 2, it's worth noting that each control has a focusPolicy property which determines how the control gets focus. The default for controls like Button is Qt.StrongFocus, which means that buttons get focus after being clicked or tabbed into. If you're seeing that a control has focus and you don't want it to, just set its focusPolicy to Qt.NoFocus:
focusPolicy: Qt.NoFocus

QML Popups not working properly with C++ application

I have an application in Qt in which I can switch between c++ app and QML app (setting central widget to one or other).
The problem is that in order to work this, I had to change my main.qml from ApplicationWindow to Page and now Dialogs and all Popups in my QML app are not working properly (modality and focus is not working at all).
My code looks like that:
QQuickWidget *view = new QQuickWidget(this);
view->setSource(QUrl(QStringLiteral("qrc:/main.qml"))); //Page
MyCppApp *myCppApp = new MyCppApp (this); //QWidget
QStackedWidget *stackedWidget = new QStackedWidget;
stackedWidget->addWidget(view);
stackedWidget->addWidget(myCppApp);
stackedWidget->setCurrentIndex(1);
setCentralWidget(stackedWidget);
I know in Popup's documentation there is that "It can be used with Window or ApplicationWindow." but is there a way to get Popups in my QML work properly?
I am using Qt 5.8 and Qt Quick Controls 2.
For the modality you should not make the dialog window part of central widget in main window (otherwise it is modal relative to what?). Invoke it from main window. And to give it modal dialog looks and behavior you can apply window flags like that:
// this view is not a part of the app main window
view->setFlags(Qt::Dialog | Qt::WindowTitleHint |
Qt::WindowStaysOnTopHint | Qt::MSWindowsFixedSizeDialogHint);
Mind that Qt::MSWindowsFixedSizeDialogHint is of course applicable on Windows only. And for setting the focus:
// to set the edit focus such trick needed
QTimer::singleShot(0, view, SLOT(setFocus()));
I use that with QML widget container. Implementation details may differ. And no QML part visible. There you may need to take care of FocusScope then.

How to set QFileDialog's parent to a QQuickView

The only window in my application is a QQuickView which is a subclass of QWindow, not of QWidget, so if I want to use a QFileDialog to give the user the option to save a file, I do not know how to set its parent to be the QQuickView. I know that the QFileDialog works without a parent, but if it does not have a parent, it is not centered over the QQuickView. This is not a big problem on its own, but on my OS (Ubuntu 13.10) a QFileDialog without a parent sometimes appears under the QQuickView window and the user sees only a “flashing” taskbar icon.
I use Qt 5.2. I initially tried to use the FileDialog type in the Qt Quick Dialogs module but it does not have some features I need (such as the defaultSuffix property).
Right, this is a serious problem of QML. You cannot utilize the QFileDialog because you don't have a QWidget app and FileDialog lacks some critical features.
See: FileDialog in QTQuick (QML): Save file under given name
At the moment we are using code from deep down in the Qt source code, which is not in the public API. It only requires a Window instead of a Widget to do modality right.
Maybe I can write a blog post about that over Christmas.

Qt Popup as a completer window

I need to make some kind of popup window that contains propositions to complete sentences in text editor (QTextPlainEdit). This window needs to be on top of all windows of this application. Also this popup mustn't interrupt typing in the text editor when it appears. I tried different types of flags for QWidget that implements this completer but all I have got is that this completer window is placed above all windows of OS (even if this application is not active) or it interrupts typing in the text editor and makes main window not active any time it appears.
What flags should I use for completer widget?
You could try to use QWidget::setWindowFlags(Qt::Window | Qt::FramelessWindowHint).
Otherwise you could use a customized version of Qt::Popup, by overriding the automatic closing behavior.
You could also try this: if you set the QTextPlainEdit's parent as the completer's parent it should do what you want, provided that the parent does not have a layout (otherwise it will not "float").
The Qt docs contain an example that implements a google-based auto-completer widget, here: http://qt-project.org/doc/qt-4.8/network-googlesuggest.html.
As far as I can tell, they do two things that might be relevant to your situation. One is the flags they set on the popup widget:
popup = new QTreeWidget;
popup->setWindowFlags(Qt::Popup);
popup->setFocusPolicy(Qt::NoFocus);
popup->setFocusProxy(parent);
The other is a custom event filter on the popup widget, which forwards most keypress-events to the editor widget, and closes the auto-completer on Enter or Escape.

Qt background task touch event

I have a Symbian Qt "background" app that displays a button type thing using CWindowDrawer derived from CActive that is visible on top of everything. I want it to be visible when the a textinput is active or the virtual keyboard is visible, preferably when a textinput is active because some phones have a hardware keyboard. When it is visible I want it to receive all touch positions as to determine if it is being pressed without it taking focus and closing the keyboard?
Basically I need a way to determine when a textinput is activated and I need a way to listen for all touch positions from a non qwidget that is also not in focus.
Any help would be appreciated.
PS. This is for Symbian Belle and Symbian C++ is also supported within a Qt application if necessary.

Resources