Closed brusand closed 11 months ago
Hey @brusand,
There are a few things wrong with your code:
You need to use the QtChart
object rather than the Chart
object
QtChart is not an instance which Pyside can interpret; it is based on the QWebEngine, which can be accessed in chart.webview
.
If you're still having issues, take a look at the example in the documentation.
Louis
i create this class on my project and it works like a charm
from lightweight_charts import LWC
from PySide6.QtWebEngineWidgets import QWebEngineView
class PySide6Chart(LWC):
def __init__(self, widget=None, volume_enabled=True):
try:
self.webview = QWebEngineView(widget)
except NameError:
raise ModuleNotFoundError('QWebEngineView was not found, and must be installed to use QtChart.')
super().__init__(volume_enabled)
self.webview.loadFinished.connect(self._on_js_load)
self.webview.page().setHtml(self._html)
def run_script(self, script): self.webview.page().runJavaScript(script)
def _on_js_load(self):
self.loaded = True
for func, args, kwargs in self.js_queue:
getattr(super(), func)(*args, **kwargs)
def get_webview(self): return self.webview
class CandlestickChart(QWidget):
def __init__(self):
super().__init__()
self.df = pd.DataFrame()
#self.chart = Chart(c)
self.chart = PySide6Chart(volume_enabled=False)
#self.chart = QtChart(self)
self.layout = QVBoxLayout(self)
#df = pd.read_csv('result.csv')
#self.chart.set(df)
self.layout.addWidget(self.chart.get_webview())
Expected Behavior
add a chart with PySide6 Layout
Current Behaviour
TypeError: 'PySide6.QtWidgets.QBoxLayout.addItem' called with wrong argument types: PySide6.QtWidgets.QBoxLayout.addItem(Chart)
Reproducible Example
Environment