Feb-11-2022, 06:55 PM
Hi, I need draw charts in two tabs. It there any easy way how to do it? Thank you for help.
This is my code.
This is my code.
import sys from PyQt5.QtWidgets import QMainWindow, QApplication, QPushButton, QWidget, QAction, QTabWidget,QVBoxLayout from PyQt5.QtGui import QIcon from PyQt5.QtCore import pyqtSlot from PyQt5.QtWidgets import QLabel class App(QMainWindow): def __init__(self): super().__init__() self.title = 'CHART' self.left = 0 self.top = 0 self.width = 800 self.height = 600 self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) self.table_widget = MyTableWidget(self) self.setCentralWidget(self.table_widget) self.show() class MyTableWidget(QWidget): def __init__(self, parent): super(QWidget, self).__init__(parent) self.layout = QVBoxLayout(self) # Initialize tab screen self.tabs = QTabWidget() self.tab1 = QWidget() self.tab2 = QWidget() self.tabs.resize(300,200) # Add tabs self.tabs.addTab(self.tab1,"Tab 1") self.tabs.addTab(self.tab2,"Tab 2") # Create first tab self.tab1.layout = QVBoxLayout(self) self.l = QLabel() self.l.setText("Line chart 1") self.tab1.layout.addWidget(self.l) self.tab1.setLayout(self.tab1.layout) # Create second tab self.tab2.layout = QVBoxLayout(self) self.l = QLabel() self.l.setText("Line chart 2") self.tab2.layout.addWidget(self.l) self.tab2.setLayout(self.tab2.layout) # Add tabs to widget self.layout.addWidget(self.tabs) self.setLayout(self.layout) if __name__ == '__main__': app = QApplication(sys.argv) ex = App() sys.exit(app.exec_())