Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Adding an object to a QTabWidget
Forum Updated to NodeBB v4.3 + New Features

Adding an object to a QTabWidget

Scheduled Pinned Locked Moved Solved Qt for Python
3 Posts 2 Posters 438 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.
  • G Offline
    G Offline
    GaryN
    wrote on last edited by
    #1

    I have the following experimental code:

    import sys
    
    from PyQt6.QtCore import Qt, QSize
    from PyQt6.QtWidgets import (
    	QApplication,
    	QMainWindow,
    	QWidget,
    	QTabWidget,
    	QToolBar,
    )
    
    
    class MainWindow(QMainWindow):
    	
    	def __init__(self):
    		
    		super().__init__()
            
    		self.setWindowTitle("StelCor")
    		self.setFixedSize(QSize(1024, 768))
            
    		tabs = QTabWidget()
    		tabs.setTabPosition(QTabWidget.TabPosition.West)
    
    		tabs.addTab(QWidget(), "Initialisation")
    		tabs.addTab(QWidget(), "Graphing")
    		       
    		self.setCentralWidget(tabs)
    
    app = QApplication(sys.argv)
    
    window = MainWindow()
    window.show()
    
    sys.exit(app.exec())
    

    This creates two tabs within my MainWindow.

    I now want to add objects (a QLabel, a textbox, etc) to each tab.

    How do I do this?

    jsulmJ 1 Reply Last reply
    0
    • G GaryN

      I have the following experimental code:

      import sys
      
      from PyQt6.QtCore import Qt, QSize
      from PyQt6.QtWidgets import (
      	QApplication,
      	QMainWindow,
      	QWidget,
      	QTabWidget,
      	QToolBar,
      )
      
      
      class MainWindow(QMainWindow):
      	
      	def __init__(self):
      		
      		super().__init__()
              
      		self.setWindowTitle("StelCor")
      		self.setFixedSize(QSize(1024, 768))
              
      		tabs = QTabWidget()
      		tabs.setTabPosition(QTabWidget.TabPosition.West)
      
      		tabs.addTab(QWidget(), "Initialisation")
      		tabs.addTab(QWidget(), "Graphing")
      		       
      		self.setCentralWidget(tabs)
      
      app = QApplication(sys.argv)
      
      window = MainWindow()
      window.show()
      
      sys.exit(app.exec())
      

      This creates two tabs within my MainWindow.

      I now want to add objects (a QLabel, a textbox, etc) to each tab.

      How do I do this?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @GaryN said in Adding an object to a QTabWidget:

      How do I do this?

      Add widgets to the widgets you set as tabs:

      w = QWidget()
      button = QPushButton(w) // button is child of w
      ...
      tabs.addTab(w, "Initialisation")
      

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      G 1 Reply Last reply
      2
      • jsulmJ jsulm

        @GaryN said in Adding an object to a QTabWidget:

        How do I do this?

        Add widgets to the widgets you set as tabs:

        w = QWidget()
        button = QPushButton(w) // button is child of w
        ...
        tabs.addTab(w, "Initialisation")
        
        G Offline
        G Offline
        GaryN
        wrote on last edited by
        #3

        @jsulm
        Thank you; I have marked this as a solution.

        I did go off and explore other ideas and am now using a separate class to define all the parts of each tab.

        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