Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to promote the ui file to the QtGraphviews window?
Qt 6.11 is out! See what's new in the release blog

How to promote the ui file to the QtGraphviews window?

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 459 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    EClassBox
    wrote on last edited by
    #1

    I already made a ui file used 2 classess.
    Chart.py

    import sys, time, datetime, pyupbit
    import pandas as pd
    import finplot as fplt
    from PyQt5 import QtWidgets, uic
    from PyQt5.QtWidgets import *
    from PyQt5.QtCore import *
    
    # candle chart setting
    fplt.display_timezone = datetime.timezone.utc
    fplt.candle_bull_color = "#FF0000"
    fplt.candle_bull_body_color = "#FF0000"
    fplt.candle_bear_color = "#0000FF"
    
    chart = uic.loadUiType("chart.ui")[0]
    class Worker(QThread):
        timeout = pyqtSignal(pd.DataFrame)
        def __init__(self):
            super().__init__()
    
        def get_ohlcv(self):
            self.df = pyupbit.get_ohlcv(ticker="KRW-XRP", interval="minute1")
            self.df = self.df[['open', 'high', 'low', 'close']]
            self.df.columns = ['Open', 'High', 'Low', 'Close']
    
        def run(self):
            self.get_ohlcv()
    
            while True:
                data3 = pyupbit.get_current_price("KRW-XRP", verbose=True)
                price3 = data3['trade_price']
                time_stamp = data3['trade_timestamp'] / 1000
                cur_min_time_stamp = time_stamp - time_stamp % (60)
                cur_min_dt = datetime.datetime.fromtimestamp(cur_min_time_stamp)
    
                if cur_min_dt > self.df.index[-1]:
                    self.get_ohlcv()
                else:
                    self.df.iloc[-1]['Close'] = price3
                    if price3 > self.df.iloc[-1]['High']:
                        self.df.iloc[-1]['High'] = price3
                    if price3 < self.df.iloc[-1]['High']:
                        self.df.iloc[-1]['Low'] = price3
    
                CurrentPrice3 = pyupbit.get_current_price("KRW-XRP")
                print("Current Price of KRW-XRP :", CurrentPrice3)
    
                self.timeout.emit(self.df)
                time.sleep(1)
    
    class MyWindow(QWidget, chart):
        def __init__(self):
            super().__init__()
            self.setupUi(self)
            self.df = None
            self.plot = None
            
            self.w = Worker()
            self.w.timeout.connect(self.update_data)
            self.w.start()
    
            self.timer = QTimer(self)
            self.timer.start(1000)
            self.timer.timeout.connect(self.update)
    
            self.ax = fplt.create_plot(init_zoom_periods=100)
            self.axs = [self.ax]
    
            self.gridLayout_2.addWidget(self.ax.vb.win, 0, 0)
    
        def update(self):
            if self.df is not None:
                if self.plot is None:
                    self.plot = fplt.candlestick_ochl(self.df[['Open', 'Close', 'High', 'Low']])
                    fplt.show(qt_exec=False)
                else:
                    self.plot.update_data(self.df[['Open', 'Close', 'High', 'Low']])
    
        @pyqtSlot(pd.DataFrame)
        def update_data(self, df):
            self.df = df
    
    if __name__ == "__main__":
        app = QApplication(sys.argv)
        window = MyWindow()
        window.show()
        app.exec_()
    

    and chart.ui has 1 gridLayout in 1 graphicsView
    31b66cce-bfd7-4307-b08e-61d8cf6d1dc6-image.png

    then I' want to print out the chart.ui on the QGraphicsview screen in the main.ui.
    But I don't know about how to promote QGrphicsview widget and write the Python code.
    Could you please tell me what I should do?

    02ed9114-cc8a-49d2-99da-4fc8f3e0f371-image.png

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved