Qt rendering using OpenGL - qt

I'm working on a QML application for an embedded platform which includes a GridView widget containing images. It's important for me that scrolling through the GridView will be smooth and will not put load on the CPU. Can I expect Qt to use OpenGL to render the GridView?

I faced with the same problem.
QApplication::setGraphicsSystem(QLatin1String("opengl"));
haven`t work for me. So i set the OGWidget as a viewport:
QDeclarativeView mainwindow;
mainwindow.setSource(QUrl::fromLocalFile("./qml/app.qml"));
QGLFormat format = QGLFormat(QGL::DirectRendering); // you can play with other rendering formats like DoubleBuffer or SimpleBuffer
format.setSampleBuffers(false);
QGLWidget *glWidget = new QGLWidget(format);
glWidget->setAutoFillBackground(false);
mainwindow.setViewport(glWidget);
and do not forget to add opengl in *.pro file.

Depending on your platform use
QApplication::setGraphicsSystem(QLatin1String("opengl"));
or (Symbian)
QApplication::setGraphicsSystem(QLatin1String("openvg"));
before you instantiate the QApplication object.

By default Qt does not use the OpenGL render backend. You can enforce it by using a QGlWidget. In your case, as you want to use a stock widget, you can set the render backend as a command line option:
<binary name> -graphicssystem opengl

Related

QtWebEngine doesn't support JavascriptCanCloseWindows

In QtWebkit, using QWebSettings class, I could enable like the permission to close the window using the JavaScript command window.close();:
setAttribute(QWebSettings::JavascriptCanCloseWindows, true);
But in QtWebEngine, such an attribute doesn't exist: http://doc.qt.io/qt-5/qwebenginesettings.html#WebAttribute-enum
How to allow JavaScript to close any QWebEngineView using window.close()?
Indeed, this attribute doesn't exist anymore in the Qt WebEngine.
However, you can close any views using the signal windowCloseRequested from your QWebEnginePage, and connecting it to a slot where you close the window. There is an example of use in the Demo Browser example, in the file webview.cpp:
connect(page(), &WebPage::windowCloseRequested, this, &QWidget::close);

Zoom feature for QWebEngine does not work

I created simple project for displaying local .html page.
I used Qt5.4 with QWebView there. But after switching to Qt5.6 I noticed
that Qt WebKit is deprecated and not supported any more.
Thus I decided to replace Qt WebKit functionality with one from the
Qt WebEngine.
After replacing QWebView with QWebEngineView
I investigated that setZoomFactor method has no effect.
Is it known issue? How can I handle with this?
EDIT:
An interesting thing have been investigated recently. I use setHtml method for setting content of local .html files to my QWebEngineView. These files also contain references to images. So I set baseUrl parameter as a relative path to required images. In that case using of setZoomFactor method has no effect.
But when I don't set relative path to images as parameter, images are absent on QWebEngineView but zoom functionality works. Any ideas what is wrong here?
Setting zoomFactor for QML WebEngineView in Qt 5.11 using QML zoomFactor property or C++ setZoomFactor (private-API) did not work as expected. I discovered from comments in QT Bug 51992 that it works when set after a page load.
QML solution:
WebEngineView {
// ...
onLoadingChanged: {
zoomFactor = 0.75
}
}
QWebEngineView solution: connect to the loadFinished signal, and set zoomFactor after each page load:
main.cpp (after engine.load call):
QWebEngineView *webView; // = ...
QObject::connect(webView, &QWebEngineView::loadFinished,
[=](bool arg) {
webView->setZoomFactor(zoomFactor);
});
It seems to be a known bug in this version of Qt. You can check by yourself here : Qt Bug 51992.
Basically, it is said that :
This looks like a known glitch that is currently happening because of
the Chromium API that we use for setting the zoom factor.
And also :
Chromium limits the zoom factor to a maximum of 5.0 - any calls with a
number higher than that will have no effect.
Hope that will help you.
The setZoomFactor does not function properly in the QT 5.15 release.
Call setZoomFactor multiple times to resolve the problem.
WebEngineView {
function setZoomFactor(real) {
zoomFactor = real
zoomFactor = real
zoomFactor = real
}
}

How to access the set qt stylesheet properties (css like grammar), or is there an css to xml converter?

Hy,
i m working on a qt application styled by a stylesheet, set like
QApplication qApplication(argc, argv);
QFile styleFile("myStyleFile.stylesheet");
bool check = styleFile.open(QFile::ReadOnly);
qApplication.setStyleSheet(styleFile.readAll());
the important window of this application uses a QGraphicsScene (which items are not styleable with stylesheets).
But i wannt a unique look.
So the questions are:
1.) Is there a way to access the set stylesheet properties ( like getProperty("QMenu::item:selected") )?
2.) or does anyone know a css-syntax to xml-file tool? (than one could access the set properties with the qt xml/dom support)
I know that some special properties can be accessed like
QColor mainWindowbackgroundColor =
palette().color( QWidget::backgroundRole() );//Get the backgroundcolor set by stylesheet.
but i am searching for a way to access ALL set properties.
Thank you!
I think you will need to use private Qt classes to do this. This is generally not a good idea as the interfaces are internal and subject to change.
In the Qt (4.8.4) sources \src\gui\text\qcssparser_p.h header the QCss namespace is declared.
Whilst I haven't tried this, it looks like you will need to create a QCss::Parser, call parse to get a QCss::StyleSheet. This object contains the parsed data including a vector of QCss::StyleRule which matches QCss::Selector and QCss::Declaration together, have a look at the comment above the QCss::Declaration to see how it is all broken down.
Final Warning: Using Qt private interfaces is liable to cause maintenance problems - don't do it without a very good reason.

Transparency of QDeclarativeView containing QML on top of a QWidget playing a video (using either phonon or libvlc)

I am currently developing a video player.
The GUI as the topmost layer is written in QML. It should be transparent to lower layers. It contains control elements, some Lists etc., It's displayed using a QDeclarativeView.
Description
QDeclarativeView *upperLayer = new QDeclarativeView(this);
upperLayer->setSource(QUrl("/home/projects/QtVideo/qml/videoControl.qml"));
upperLayer->setStyleSheet(QString("background: transparent");
upperLayer->setResizeMode(QDeclarativeView::SizeRootObjectToView);
uperLayer->showFullScreen();
The layer underneath is a QWidget: I use the libvlc to display the video content
in this widget.
Reason: I am receiving MPEG-TS, which can not be decoded by phonon, afaik. Therefore I need the libvlc to decode the incoming *.ts stream and put the output onto the display.
QWidget *lowerLayer = new QWidget(this);
lowerLayer.setGeometry(QString("background: red"));
QUrl* url = new QUrl("file:///home/projects/QtVideo/video.ts");
libvlc_instance_t*vlcObject;
libvlc_media_t*vlcMedia;
libvlc_media_player_t*vlcPlayer;
vlcPlayer = NULL;
if(vlcObject = libvlc_new(argc, argv)) == NULL)
{
printf("Not able to initialize";
exit(1);
}
if(vlcPlayer && libvlc_media_player_is_playing(vlcPlayer))
{
libvlc_media_player_stop(vlcPlayer);
}
vlcPlayer = libvlc_media_player_new(vlcObject);
vlcMedia = libvlc_media_new_location(vlcObject, url.toString().toUtf8().constData());
libvlc_media_player_set_media(vlcPlayer, vlcMedia);
#if defined(Q_OS_MAC)
libvlc_media_player_set_nsobject(vlcPlayer, lowerLayer->winId());
#elif defined(Q_OS_UNIX)
libvlc_media_player_set_x_window(vlcPlayer, lowerLayer->winId());
#elif defined(Q_OS_WIN)
libvlc_media_player_set_hwnd(vlcPlayer, lowerLayer->winId());
#endif
libvlc_media_player_play(vlc_player);
Both Elements, the QDeclarativeView and the QWidget
are embedded in a QMainWindow, lowerLayer created before the upperLayer,
upperLayer Transparent to the lowerLayer.
The Problem:
As long as the lowerLayer is displaying static elements such as a picture, or some colored shapes, everything works fine, full transparency and functionality.
As soon as I start displaying a video, such as the described *.ts using the libvlc OR some random video using the Phonon::VideoPlayer, the parts of the upperLayer which are above the video parts of the lowerLayer are displayed in the color of the lowerLayer(default: gray), the parts of the upperLayer which are positioned above parts of the lowerLayer or others which do not contain video elements are displayed in correct behaviour.
Question:
Is there any posibility and if, how, to get the upperLayer transparent, even if there is a video playing?
Are you still fighting with this issue? I, sadly, do not have a satisfying answer for you. The best I can do is point you to reasons why it doesn't work:
http://lists.trolltech.com/qt-interest/2007-02/thread01061-0.html
See Message #4 in the link above.
I have tried many different methods to get transparent painting over a video (specifically Phonon::VideoPlayer) using Qt. The only method I've found so far, is to set the overlaying QWidget as a toolTip doing something like
pWidget->setWindowFlags(Qt::ToolTip)
Depending on what exactly you're wanting to do this may be sufficient, but (in my opinion) it's a hack at best. I'm actively struggling with this issue and if I can find some sort of solution, I'll be sure to post it here.
Best of luck.
you're using direct rendering (by passing the wid of the widget) which draws the video overtop at that geometry:
libvlc_media_player_set_x_window
you need to use offscreen rendering and draw that to your qwidget. this can be done with an opengl context (complicated) or using the callback methods available in libvlc.
if you use the display callback (libvlc_video_display_cb) libvlc will also generate lock/unlock methods also, if you need. in this method libvlc will expect some parameters to be set such as canvas geometry and pixel format.
that said, phonon has a libvlc backend which might help, but may still use direct rendering depending on some factors..

How to know that widget is currently is running in Qt Designer

How can I in code of the custom Qt widget know that it is currently instantiated in Qt designer?
Use case:
I build a complex custom widget that has several child widgets like QPushButton, QLabel etc.
As application logic require, when widget is created most of those sub component are not visible but in design time when I put it on a form I would like to see them.
To be able to play with style sheet at design time.
Currently what I get is a empty is only a result of constructor - minimal view (actually empty in my case).
What I am looking for is to be able to do something like
MyQWidget::(QWidget *parent)
{
....
if(isRunningInDesigner())
{
myChildWidget1->setVisible(true);
myChildWidget2->setVisible(true);
myChildWidget3->setVisible(true);
}
else
{
myChildWidget1->setVisible(false);
myChildWidget2->setVisible(false);
myChildWidget3->setVisible(false);
}
....
}
So what should I put in to this bool isRunningInDesigner() ?
From the Qt Designer manual:
To give custom widgets special behavior in Qt Designer, provide an implementation of the initialize() function to configure the widget construction process for Qt Designer specific behavior. This function will be called for the first time before any calls to createWidget() and could perhaps set an internal flag that can be tested later when Qt Designer calls the plugin’s createWidget() function.
Those are methods from the QDesignerCustomWidgetInterface plugin interface. In short: you tell the widget to behave differently when Qt Designer asks your plugin to create instances of your custom widget.

Resources