Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PYQT charts in tabs
#1
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.

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_())
Reply


Messages In This Thread
PYQT charts in tabs - by frohr - Feb-11-2022, 06:55 PM
RE: PYQT charts in tabs - by Axel_Erfurt - Feb-11-2022, 07:48 PM
RE: PYQT charts in tabs - by frohr - Feb-12-2022, 05:15 PM
RE: PYQT charts in tabs - by Axel_Erfurt - Feb-12-2022, 05:54 PM
RE: PYQT charts in tabs - by frohr - Feb-12-2022, 06:39 PM
RE: PYQT charts in tabs - by Axel_Erfurt - Feb-12-2022, 06:59 PM
RE: PYQT charts in tabs - by Axel_Erfurt - Feb-12-2022, 07:27 PM
RE: PYQT charts in tabs - by frohr - Feb-13-2022, 11:40 AM
RE: PYQT charts in tabs - by Axel_Erfurt - Feb-13-2022, 12:34 PM
RE: PYQT charts in tabs - by frohr - Feb-13-2022, 01:48 PM
RE: PYQT charts in tabs - by Axel_Erfurt - Feb-13-2022, 04:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I want to create custom charts in Python. js1152410 1 566 Nov-13-2023, 05:45 PM
Last Post: gulshan212
  Buttons not working in tabs kenwatts275 2 1,412 May-02-2022, 04:45 PM
Last Post: kenwatts275
  create new tabs and populate using python reggie4 2 2,287 Jan-23-2021, 11:25 PM
Last Post: Larz60+
  Line charts error "'isnan' not supported for the input types," issac_n 1 2,444 Jul-22-2020, 04:34 PM
Last Post: issac_n
  HELP TabError: inconsistent use of tabs and spaces in indentation blackjesus24 2 3,602 Jan-30-2020, 10:25 AM
Last Post: blackjesus24
  Setting Tabs in a listbox scratchmyhead 2 2,851 Nov-12-2019, 11:18 PM
Last Post: scratchmyhead
  removing spaces/tabs after used .strip() zarize 0 1,618 Sep-11-2019, 12:46 PM
Last Post: zarize
  Is there any way to transfer charts generated from excel to powerpoint? zcabaaf 1 7,989 Aug-05-2019, 07:34 AM
Last Post: zcabaaf
  removing tabs from input text jenya56 3 3,277 Mar-28-2019, 03:10 PM
Last Post: DeaD_EyE
  Why interpreter accepts indentation made with spaces and not those by tabs sylas 13 5,652 Jan-10-2019, 11:17 PM
Last Post: texadactyl

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020