Failed to build graphics pipeline state in qt quick application - python

I have a qt quick pyside application .I had a question before,but now another proplem is there .Just a empty window appears and then in application window I see below message.Although I have another qt quick application that I written that in c++ and there is no problem displaying it, this message is displayed!,This application is in python(pyside6)
I use Qt 6.0.2,Python 3.9.2,Qt Creator 4.14.1 and Pyside6
Failed to create vertex shader: Error 0x80070057: The parameter is incorrect.
Failed to build graphics pipeline state
*main.qml
import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15
Window {
id:mainWindow
width: 1000
height: 580
visible: true
title: qsTr("JooyaTrader")
Rectangle{
width: 152
height: 62
anchors.fill: parent
color: "red"
}
}
main.py
import sys,os
from PySide6.QtGui import QGuiApplication
from PySide6.QtQml import QQmlApplicationEngine
import PySide6
if __name__ == "__main__":
app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine()
engine.load(os.path.join(os.path.dirname(__file__), "main.qml"))
if not engine.rootObjects():
sys.exit(-1)
sys.exit(app.exec_())

The problem is caused because the backend that Qt Quick uses for rendering does not work for your case, either because there are missing libraries or the version is not according to what Qt expects. In that one solution is to set the QT_QUICK_BACKEND in "software" making the rendering do it Qt Quick 2D Renderer:
os.environ["QT_QUICK_BACKEND"] = "software"
app = QGuiApplication(sys.argv)
For more information read Scene Graph Adaptations.

Related

How to use MapType in qml?

I am working on a gui project in python, where i want to show a map using pyqt.
I've stumbled upon a way of using qml to do just that, and I was able to show a simple map, but when I try customizing it's appearance using the activeMapType property, the program only show a blank white screen. (I dont have debug messages, cause I'm not using Qt creator)
I suspect a problem is in the declaration of "map_type", but i can't figure what it is.
The python code (simply loads the qml file):
import os
from PyQt5 import QtCore, QtWidgets, QtQuickWidgets, QtPositioning
from PyQt5.QtQuick import QQuickView
from PyQt5.QtWidgets import *
if __name__ == '__main__':
app = QApplication([])
w = QtQuickWidgets.QQuickWidget()
qml_path = os.path.join(os.path.dirname(__file__), "main.qml")
w.setSource(QtCore.QUrl.fromLocalFile(qml_path))
w.setResizeMode(QtQuickWidgets.QQuickWidget.SizeRootObjectToView)
w.show()
app.exec()
Main.qml:
import QtQuick 2.11
import QtPositioning 5.11
import QtLocation 5.11
Rectangle {
id:rectangle
width: 640
height: 480
Plugin {
id: osmPlugin
name: "osm"
}
MapType {
id: map_type
description: "type of the map"
mobile: false
name: "test"
night: true
}
property variant locationTC: QtPositioning.coordinate(44.951, -93.192)
Map {
id: map
activeMapType: map_type
anchors.fill: parent
plugin: osmPlugin
center: locationTC
zoomLevel: 10
copyrightsVisible: false
}
}

PySide6 comes with segmentation fault on Mac

I am using Python 3.8.6 and PySide 6.0.1 and get a segmentation fault running the below sample.
When I comment the Text {} element the sample runs.
import sys
from PySide6.QtGui import QGuiApplication
from PySide6.QtQml import QQmlApplicationEngine
if __name__ == "__main__":
app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine("view.qml")
if not engine.rootObjects():
sys.exit(-1)
sys.exit(app.exec_())
import QtQuick 2.0
import QtQuick.Controls 2.5
ApplicationWindow
{
width: 640
height: 480
visible: true
title: "QML Demo"
Text
{
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
text: "Hello World"
}
}
I can't test your code on Mac but as a suggestion you can remove all version numbers from imports in QML.
This is the only difference I can see here between PyQt5 and PyQt6.
(however your code works on Ubuntu 20.04)

Using QtCharts in Qt Creator with python

I am using Qt Creator to create a QtQuick program using Python. I want to add the QtCharts module to my QML files, but I get the error message
QML module not found (QtCharts)
In a QtQuick project using C++, one would include QtCharts by adding QT += charts in the .pro file.
Is there a similar command to add in the main.pyproj file?
Note that the program runs correctly when built through the python script, but I want to access the features used by the designer in Qt Creator.
The main.pyproject is as follows:
{"files": ["main.py","frontend/main.qml"]}
The main.py file:
import os
import sys
import PyQt5.QtQml
import PyQt5.QtCore
import PyQt5.QtWidgets
if __name__ == '__main__':
os.environ['QT_QUICK_CONTROLS_STYLE'] = 'Default'
app = PyQt5.QtWidgets.QApplication(sys.argv)
engine = PyQt5.QtQml.QQmlApplicationEngine()
engine.load('frontend/main.qml')
if not engine.rootObjects():
sys.exit(-1)
sys.exit(app.exec_())
the frontend/main.qml file:
import QtQuick 2.12
import QtQuick.Controls 2.13
import QtQuick.Layouts 1.12
import QtCharts 2.10
ApplicationWindow {
id: window
visible: true
title: 'Neuron Network Sandbox'
ChartView {
width: 400
height: 300
antialiasing: true
PieSeries {
id: pieSeries
PieSlice { label: "eaten"; value: 94.9 }
PieSlice { label: "not yet eaten"; value: 5.1 }
}
}
}

QML does not play well with system theme [duplicate]

I have a problem with Toolbar when I use the qml file with PyQt5. The result is not the seem : no background image when mouse is over, image no resize automatically.
I want to know if it's normal.
How can I do for have the same result with PyQt5
The result with qmlscene:
The result with Python:
Thanks you for your help.
File : _test.py
from PyQt5.QtCore import (
pyqtProperty,
pyqtSignal,
pyqtSlot,
QAbstractListModel,
QModelIndex,
QObject,
Qt,
QTimer,
)
from PyQt5.QtGui import QGuiApplication
from PyQt5.QtQml import QQmlApplicationEngine
from PyQt5.QtQuick import QQuickView
class MainWindow(QObject):
def __init__(self, parent=None):
super().__init__(parent)
if __name__ == "__main__":
import sys
app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine()
engine.quit.connect(app.quit)
main_window = MainWindow()
engine.load("_test.qml")
if not engine.rootObjects():
sys.exit(app.exec_())
sys.exit(app.exec())
File : _test.qml
import QtQuick 2.4
import QtQuick.Layouts 1.1
import QtQuick.Controls 1.3
import QtQuick.Controls.Styles 1.3
ApplicationWindow {
width: 500
height: 200
visible: true
ToolBar {
Layout.fillWidth: true
RowLayout {
anchors.fill: parent
ToolButton {
//width: parent.height
anchors.margins: 4
iconSource: "ico/abacus.png"
}
ToolButton {
width: parent.height
Image {
source: "ico/quitter.png"
anchors.fill: parent
anchors.margins: 4
}
}
ToolButton {
width: parent.height
iconSource: "ico/start.png"
anchors.margins: 4
}
ToolButton {
width: parent.height
Image {
source: "ico/stop.png"
anchors.fill: parent
anchors.margins: 4
}
}
}
}
}
Analyzing the source code of qmlscene and testing with the --apptype option I get the following:
qmlscene _test.qml --apptype gui
qmlscene _test.qml --apptype widgets
So analyzing the fundamental difference is that QApplicacion is being used and not QGuiApplication, so internally it should activate some flag that scales the icons.
Considering the above, the solution is:
from PyQt5.QtCore import QUrl
from PyQt5.QtWidgets import QApplication
from PyQt5.QtQml import QQmlApplicationEngine
if __name__ == "__main__":
import os
import sys
app = QApplication(sys.argv)
engine = QQmlApplicationEngine()
current_dir = os.path.dirname(os.path.realpath(__file__))
file = os.path.join(current_dir, "_test.qml")
engine.load(QUrl.fromLocalFile(file))
if not engine.rootObjects():
sys.exit(-1)
sys.exit(app.exec_())
According to the docs of Qt Quick Controls 1:
Note: We are using QApplication and not QGuiApplication in this
example. Though you can use QGuiApplication instead, doing this will
eliminate platform-dependent styling. This is because it is relying on
the widget module to provide the native look and feel.
So it seems that the scaling of the icons is part of the style of the platform.
Each type of project requires a QXApplication:
Console application: You can use any of the 3 types of QXApplication, but using QCoreApplication is the most optimal since the other QXApplication require that they have a window system that in that case is an unnecessary requirement.
QML Application: It requires at least one QGuiApplication, but for certain ones such as the need to use the styles of each platform it is necessary to use QApplication.
Qt Widgets Application: A QApplication is necessary because QWidgets use the styles of each platform.
The fact that sizes change, is this a problem of QtQuick.Controls 1?
Yes, one of the main differences between QQC1 and QQC2 is that the first one is developed to support desktop platforms so you use the styles, unlike the second one that is designed for embedded systems where the main objective is performance. For more information read Differences with Qt Quick Controls 1
Conclusions:
If you want your GUI made with QML to respect the styles of your desktop platform then you must use QQC1 with QApplication.
If your goal is that the style of your application does not respect the style of the desktop in addition to wanting more performance you should use QQC2 with QGuiApplication.

Utilizing QtQuick Controls from PyQt5

First of all, I tried to use QtQuick from PySide. The latest PySide as of today wraps Qt 4.8, which doesn't have an actively developed desktop components. (colibri is there, but that's not for desktop, and it's buggy).
PyQt seems to win here, since the latest version (5.2.1 as of today), wraps Qt 5, which has QtQuick controls ready.
I've looked at many of the examples under Lib/site-packages/PyQt5/examples/quick, all of them work, but none of them use QtQuick Controls.
I am trying a very simple qml here:
//main.qml
import QtQuick.Controls 1.2
ApplicationWindow {
title: "My Application"
Button {
text: "Push Me"
anchors.centerIn: parent
}
}
and a python file:
from PyQt5.QtWidgets import QApplication
from PyQt5.QtQml import QQmlApplicationEngine
import sys
if __name__ == "__main__":
app = QApplication(sys.argv)
engine = QQmlApplicationEngine("main.qml")
engine.quit.connect(app.quit)
sys.exit(app.exec_())
but i'm having this error:
.../main.qml:1 module "QtQuick.Controls" version 1.2 is not installed
Can I use QtQuick Controls from PyQt5?. And if so, how?. I can't find it anywhere.
Did you try to use QtQuick.Controls 1.0, it works fine on my system

Categories