I am trying to make the QtVirtualKeyboard example work with QQuickWidget instead of QQuickView. For QuickView, I use the following main.cpp code, which works fine for me:
#include <QQuickView>
#include <QGuiApplication>
#include <QQmlEngine>
int main(int argc, char *argv[])
{
qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
QGuiApplication app(argc, argv);
QQuickView view(QString("qrc:/%2").arg(MAIN_QML));
view.setResizeMode(QQuickView::SizeRootObjectToView);
view.show();
return app.exec();
}
I run into problems, when changing to QQuickWidgets with the following implementation of main.cpp:
#include <QQuickWidget>
#include <QApplication>
#include <QQmlEngine>
int main(int argc, char *argv[])
{
qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
QApplication app(argc, argv);
QQuickWidget w(QString("qrc:/%2").arg(MAIN_QML));
w.setResizeMode(QQuickWidget::SizeRootObjectToView);
w.show();
return app.exec();
}
When I hit the input fields, the virtual keyboard shows up, but when I start typing at the keyboard, I get the message "input method is not set", which seems to be related to the input method plugin. No chars appear in the input fields.
Any ideas? The QML-code didn't change between the above variants of main.cpp
BTW: I am using Linux, gcc, Qt 5.9.0, EGLFS plugin
Thanks for any suggestions!
Regards,
Patrick
Found the solution for QML looking through inputMethod documentation. Following workaround works for me:
TextArea {
...
onActiveFocusChanged: {
if(activeFocus) {
Qt.inputMethod.update(Qt.ImQueryInput)
}
}
}
Works with other controls as well.
Of course InputPanel should be defined in ApplicationWindow like this:
ApplicationWindow {
...
InputPanel {
id: inputPanel
...
}
}
Related
When setting an hyperlink to a QTextBrowser, I would like that link not to be underlined. In previous versions of Qt (e.g. 2,3,4), there used to be a setLinkUnderline(bool) method which probably did the job. How to do this with Qt5 ?
thanks
A possible solution is to eliminate the underline using css:
#include <QApplication>
#include <QTextBrowser>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTextBrowser w;
w.document()->setDefaultStyleSheet("a{ text-decoration: none; }");
w.append("Stack Overflow");
w.show();
return a.exec();
}
I want to know how to set window title in Qt in maximized mode.
window->setWindowtitle("window");
But this does not work in maximized mode.
playback_main *pbw = new playback_main;
pbw->setWindowTitle("PlayBack");
pbw->showMaximized();
This is not working.
Your code works for me on a QMainWindow in, admittedly, qt 4.7. Do you need to force an update with either of:
pbw->update();
qApp->processEvents();
is pbw a QMainWindow or just a widget?
I've tried the following code on linux which works too:
#include <QApplication>
#include <QMainWindow>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMainWindow w;
w.setWindowTitle("testing");
w.showMaximized();
return a.exec();
}
Let's say we have a barebones QWebView:
#include <QApplication>
#include <QWebView>
int main(int argc, char** argv)
{
QApplication app(argc, argv);
QWebView view;
view.show();
view.setUrl(QUrl("http://google.com"));
return app.exec();
}
How can I display a graphic overlay, preferably fullscreen with transparency and minimal animation (like timer/beachball/etc.) from when the page starts loading till it's finished? Should also be triggered when url changes from within the QWebView.
You can use the LoadingOverlay class provided in this answer to draw an overlay over any QWidget. In your case, show the overlay on top of the QWebView when the signal loadStarted is triggered and hide it, when the signal loadFinished is triggered.
The following code should get you started. I put the code from the linked answer into overlay.h, the subclass of QWebView which handles the showing/hiding of the overlay is in webview.h:
webview.h
#include "overlay.h"
#include <QWebView>
class WebView : public QWebView
{
Q_OBJECT
public:
WebView(QWidget * parent) : QWebView(parent)
{
overlay = new LoadingOverlay(parent);
connect(this,SIGNAL(loadFinished(bool)),this,SLOT(hideOverlay()));
connect(this,SIGNAL(loadStarted()),this,SLOT(showOverlay()));
}
~WebView()
{
}
public slots:
void showOverlay()
{
overlay->show();
}
void hideOverlay()
{
overlay->hide();
}
private:
LoadingOverlay* overlay;
};
main.cpp
#include <QApplication>
#include "overlay.h"
#include "webview.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
ContainerWidget base;
Webview w(&base);
base.show();
w.load(QUrl("http://google.com"));
return a.exec();
}
For a QWidget we can test if it is displayed in full-screen with flags() & Qt::WindowFullScreen.
The same doesn't seem to work with QQuickView (which is a QQuickWindow which is a QWindow), as QWindow::flags() always returns Qt::WindowMinimized, whatever the reason might be. I display the window using this code:
QQuickView w;
w.setSource(...);
w.show(); /* or */ w.showFullScreen();
In Qt 5.1, QWindow::visibility() was introduced. It returns a new enum type which contains QWindow::FullScreen and behaves properly.
How can I test if a QWindow is shown in full-screen in Qt 5.0.x? I want to implement a "toggle full-screen" function. Keeping track of the current state seems to be the wrong way (yet it would be a possible work-around). I don't understand why QWindow::flags() returns Qt::WindowMinimized...
Code to reproduce issue (press RETURN to see the output of QWindow::flags()):
test.qml
import QtQuick 2.0
Rectangle {
signal test();
width: 100; height: 100
focus: true
Keys.onReturnPressed: test()
}
main.cpp
#include <QGuiApplication>
#include <QQuickView>
#include <QQuickItem>
#include <QDebug>
class Test : public QObject {
Q_OBJECT
public slots:
void test() {
QQuickItem *item = qobject_cast<QQuickItem*>(sender());
QQuickWindow *window = item->window();
qDebug() << window->flags(); // Will print 0x1 == Qt::WindowMinimized
}
};
int main(int argc, char *argv[])
{
QGuiApplication a(argc, argv);
QQuickView w;
w.setSource(QUrl("...(relative path to the qml file from above)..."));
w.show(); // Please also test w.showFullScreen();
QObject::connect(w.rootObject(), SIGNAL(test()),
new Test, SLOT(test()));
return a.exec();
}
#include "main.moc"
test.pro
QT += quick
TEMPLATE = app
SOURCES += main.cpp
Use method QWindow::windowState(). It returns key Qt::WindowFullScreen that you seek.
bool isFullScreen = w.windowState().testFlag(Qt::WindowFullScreen);
I want to alternate the colors of a QComboBox. In Windows I have no problem using the view().setAlternatingRowColors(true) function. In Linux and Mac it looks like impossible. I tried also using style sheet (see following code) but I had the same kind of results (all rows with the same background color). Can you explain me what is my error?
#include <QtGui/QApplication>
#include <QComboBox>
#include <QAbstractItemView>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.setStyleSheet("QComboBox QAbstractItemView{qproperty-alternatingRowColors: true;alternate-background-color: blue;background: red;}");
QComboBox b;
b.addItem("MM_NONE");
b.addItem("MM_VERT");
b.addItem("MM_FACE");
b.addItem("MM_EDGE");
bool tt = false;
tt = b.view()->alternatingRowColors();
b.show();
return a.exec();
}
At least on my box it appears that QPalette::Base and QPalette::AlternateBase are the same color :) Changing QPalette::AlternateBase to some other color makes this code work fine:
#include <QtGui/QApplication>
#include <QComboBox>
#include <QAbstractItemView>
#include <QPalette>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QComboBox b;
b.view()->setAlternatingRowColors(true);
QPalette p = b.palette();
p.setColor(QPalette::AlternateBase, Qt::red);
b.setPalette(p);
b.addItem("MM_NONE");
b.addItem("MM_VERT");
b.addItem("MM_FACE");
b.addItem("MM_EDGE");
b.show();
return a.exec();
}