Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8312373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:08:29+00:00 2026-06-08T20:08:29+00:00

I have a python gui in qt. the gui is buit using designer. It

  • 0

I have a python gui in qt. the gui is buit using designer. It contains tabs. I want to add a plot.
My plot object is a class (called MyPlot) that inherits from QtCore.QObject. To add it to the gui, I can simply do inside my class MainWindow that inherits from QtGui.QMainWindow:

self.Myplot(self)
self.MyPlot.plot()

But I don’t know how to tell python to put the plot only in one tab. I suppose I have to do inside MainWindow something like:

self.tab(0).Myplot(self)

But I can’t find exactly what.
Someone has any clue?

Thanks!

EDIT:
Trying to have a tab that reads an ui file generated by designer in the following code fails (I am just trying to put in a tab the things I build with designer, not to add a plot yet):

import sys
from PyQt4 import QtCore, QtGui, uic


class MyWidget(QtGui.QWidget):
  def __init__(self, parent = None):
    uic.loadUi('mainwindow.ui', self)


class TabWidget(QtGui.QTabWidget):  
  def __init__(self, parent=None):  
    super (TabWidget, self).__init__(parent)  
    self.setTabsClosable(True)  
    self.tabCloseRequested.connect(self.removeTab)
    self.inside = MyWidget()

  def tabInserted(self, index):  
    self.tabBar().setVisible(self.count() > 1)  

  def tabRemoved(self, index):  
    self.tabBar().setVisible(self.count() > 1) 


class MainWindow(QtGui.QMainWindow):
  def __init__(self,parent=None):
    QtGui.QMainWindow.__init__(self, parent)


def main():
  qApp = QtGui.QApplication(sys.argv)  

  tab = TabWidget()  

  button = QtGui.QPushButton('Hello')  
  @button.clicked.connect  
  def clicked():  
    tab.addTab(QtGui.QLabel('Hello'), 'Hello')  

  tab.addTab(button, 'Button')  

  layout = QtGui.QHBoxLayout()  
  layout.addWidget(tab)  

  window = QtGui.QWidget()  
  window.setLayout(layout)  
  window.resize(600, 400)  
  window.show()  

  qApp.exec_()  

if __name__ == "__main__":
  main()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T20:08:32+00:00Added an answer on June 8, 2026 at 8:08 pm

    The normal way to use QTabWidget is to do the following:

    1. Create a QTabWidget.
    2. Create a QWidget for each of the pages in the tab dialog, but do not specify parent widgets for them.
    3. Insert child widgets into the page widget, using layouts to position them as normal.
    4. Call addTab() or insertTab() to put the page widgets into the tab widget, giving each tab a suitable label with an optional keyboard shortcut.

    http://qt-project.org/doc/qt-5.0/qtabwidget.html#details

    UPDATE:

    I created a file untitled.ui in Qt Designer with a single checkbox. I also added call to parent __init__ in MyWidget:

    import sys
    from PyQt4 import QtCore, QtGui, uic
    
    
    class MyWidget(QtGui.QWidget):
      def __init__(self, parent = None):
        QtGui.QWidget.__init__(self)
        uic.loadUi('untitled.ui', self)
    
    
    class TabWidget(QtGui.QTabWidget):  
      def __init__(self, parent=None):  
        super (TabWidget, self).__init__(parent)  
        self.setTabsClosable(True)  
        self.tabCloseRequested.connect(self.removeTab)
        self.inside = MyWidget()
    
      def tabInserted(self, index):  
        self.tabBar().setVisible(self.count() > 1)  
    
      def tabRemoved(self, index):  
        self.tabBar().setVisible(self.count() > 1) 
    
    
    class MainWindow(QtGui.QMainWindow):
      def __init__(self,parent=None):
        QtGui.QMainWindow.__init__(self, parent)
    
    
    def main():
      qApp = QtGui.QApplication(sys.argv)  
    
      tab = TabWidget()  
    
      button = QtGui.QPushButton('Hello')  
      @button.clicked.connect  
      def clicked():  
        tab.addTab(QtGui.QLabel('Hello'), 'Hello')  
    
      tab.addTab(button, 'Button')  
    
      layout = QtGui.QHBoxLayout()  
      layout.addWidget(tab)  
    
      window = QtGui.QWidget()  
      window.setLayout(layout)  
      window.resize(600, 400)  
      window.show()  
    
      qApp.exec_()  
    
    if __name__ == "__main__":
      main()
    

    And it works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a third-party GUI program that I'm wrapping with a Python class (using
I have complex GUI application written in Python and wxPython. I want it to
I'm writing an python program (gui in gtk) (linux btw.) I want to have
I have written a python program with a PyQt GUI that, using the imaplib,
I have a Python application (with GUI, using PyQt4) that gets spawned by the
I have a threaded C program that I want to launch using a Python
I have written a simple GUI in Python using the Tkinter library. This GUI
I have written a python GUI application.I want to run the code on my
Hello Guys! I started learning python GUI development. Let's say I have this script:
I have a problem with my python code. I am writing a GUI in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.