QDataVisualization
-
Hi. I am new to Qt and PySide6. I want to understand how QDataVisualization in QML works. I found a sample code on one of the example pages and tried to run it on my local system.
However, when I run the code, a window opens and immediately closes. This only happens with QDataVisualization. Can anyone advise what could be the reason for this? Thank you. The code is shown below
import QtQuick 6 import QtQuick.Controls 6 import QtDataVisualization 1.14 import QtCharts 2.14 import QtQuick.Layouts 1.14 import QtQuick.Window 2.14 import "." ApplicationWindow { title: qsTr("Test") width: 1280 height: 720 visible: true Item { width: 640 height: 480 Bars3D { width: parent.width height: parent.height Bar3DSeries { itemLabelFormat: "@colLabel, @rowLabel: @valueLabel" ItemModelBarDataProxy { itemModel: dataModel // Mapping model roles to bar series rows, columns, and values. rowRole: "year" columnRole: "city" valueRole: "expenses" } } } ListModel { id: dataModel ListElement{ year: "2012"; city: "Oulu"; expenses: "4200"; } ListElement{ year: "2012"; city: "Rauma"; expenses: "2100"; } ListElement{ year: "2012"; city: "Helsinki"; expenses: "7040"; } ListElement{ year: "2012"; city: "Tampere"; expenses: "4330"; } ListElement{ year: "2013"; city: "Oulu"; expenses: "3960"; } ListElement{ year: "2013"; city: "Rauma"; expenses: "1990"; } ListElement{ year: "2013"; city: "Helsinki"; expenses: "7230"; } ListElement{ year: "2013"; city: "Tampere"; expenses: "4650"; } } } }
-
Hi and welcome to devnet,
Can you also post the python script you use ?
As well as the PySide6 version you installed and how you installed it.On a side note, please use coding tags for your code to make it properly readable (fixed it for you).
@SGaist Hi. I am following up on my reply. Thank you
-
Hi. I am new to Qt and PySide6. I want to understand how QDataVisualization in QML works. I found a sample code on one of the example pages and tried to run it on my local system.
However, when I run the code, a window opens and immediately closes. This only happens with QDataVisualization. Can anyone advise what could be the reason for this? Thank you. The code is shown below
import QtQuick 6 import QtQuick.Controls 6 import QtDataVisualization 1.14 import QtCharts 2.14 import QtQuick.Layouts 1.14 import QtQuick.Window 2.14 import "." ApplicationWindow { title: qsTr("Test") width: 1280 height: 720 visible: true Item { width: 640 height: 480 Bars3D { width: parent.width height: parent.height Bar3DSeries { itemLabelFormat: "@colLabel, @rowLabel: @valueLabel" ItemModelBarDataProxy { itemModel: dataModel // Mapping model roles to bar series rows, columns, and values. rowRole: "year" columnRole: "city" valueRole: "expenses" } } } ListModel { id: dataModel ListElement{ year: "2012"; city: "Oulu"; expenses: "4200"; } ListElement{ year: "2012"; city: "Rauma"; expenses: "2100"; } ListElement{ year: "2012"; city: "Helsinki"; expenses: "7040"; } ListElement{ year: "2012"; city: "Tampere"; expenses: "4330"; } ListElement{ year: "2013"; city: "Oulu"; expenses: "3960"; } ListElement{ year: "2013"; city: "Rauma"; expenses: "1990"; } ListElement{ year: "2013"; city: "Helsinki"; expenses: "7230"; } ListElement{ year: "2013"; city: "Tampere"; expenses: "4650"; } } } }
Hi and welcome to devnet,
Can you also post the python script you use ?
As well as the PySide6 version you installed and how you installed it.On a side note, please use coding tags for your code to make it properly readable (fixed it for you).
-
Hi and welcome to devnet,
Can you also post the python script you use ?
As well as the PySide6 version you installed and how you installed it.On a side note, please use coding tags for your code to make it properly readable (fixed it for you).
@SGaist Thank you for your response. The PySide6 version is 6.5.0. I installed it using pip. This is the python script
import sys import os from pathlib import Path from PySide6.QtGui import QGuiApplication from PySide6.QtWidgets import QApplication from PySide6.QtQml import QQmlApplicationEngine, QmlElement from PySide6 import QtDataVisualization from PySide6.QtCore import QObject, Signal, Slot QML_IMPORT_NAME = "io.qt.textproperties" QML_IMPORT_MAJOR_VERSION = 1 class Details(QObject): def __init__(self): super().__init__() app = QApplication(sys.argv) engine = QQmlApplicationEngine() # Get Context main = Details() engine.rootContext().setContextProperty("backend", main) qml_file = Path(__file__).parent / "test_features/testfeature.qml" engine.load(qml_file) if not engine.rootObjects(): sys.exit(-1) sys.exit(app.exec())
-
Hi and welcome to devnet,
Can you also post the python script you use ?
As well as the PySide6 version you installed and how you installed it.On a side note, please use coding tags for your code to make it properly readable (fixed it for you).
@SGaist Hi. I am following up on my reply. Thank you
-
@SGaist Hi. I am following up on my reply. Thank you
@sauropodbob what happens if you add
os.environ["QSG_RHI_BACKEND"] = "opengl"
before creating theapp
object ? -
@sauropodbob what happens if you add
os.environ["QSG_RHI_BACKEND"] = "opengl"
before creating theapp
object ?@SGaist Looks like it works now. Thank you
-
@SGaist Looks like it works now. Thank you
Since you have it working now please mark the thread as solved using the "Topic Tools" button or the three doted menu beside the answer you deem correct so that the other forum members may know a solution has been found.
-
-