I need help with a py generated file that was made in QT. I use the following line

QtGui.QTabWidget.addTab(self.tabWidget, QtGui.qApp.tr("New Tab"))

and get this error

Traceback (most recent call last):
  File "C:\python\mainwindow2.py", line 349, in createInvoice
    QtGui.QTabWidget.addTab(self.tabWidget, QtGui.qApp.tr("New Tab"))
TypeError: arguments did not match any overloaded call:
  QTabWidget.addTab(QWidget, QString): argument 2 has unexpected type 'QString'
  QTabWidget.addTab(QWidget, QIcon, QString): argument 2 has unexpected type 'QString'

What am I doing wrong? I can't leave the field empty, it gives a different error.

Recommended Answers

All 5 Replies

why dont you try pyqt forum my friend. :)

tabwidget = QtGui.QTabWidget()
widget = QtGui.QWidget()
layout = QtGui.QGridLayout(widget)

tabwidget.addTab(widget, QString.fromUtf8("New Tab"))

Thanks very much for your help. I will try to be more diligent with the tags I use.
Please let me summarize, the basics are build the widget then add the widget to the tabwidget as a page. Why do you need to do the layout?

Here is typical example of the PyQt QTabWidget() tested with Python27 and PyQT4.8.2

# explore the PyQt QTabWidget()

from PyQt4.QtCore import *
from PyQt4.QtGui import *

class MainWindow(QWidget): 
    def __init__(self): 
        QWidget.__init__(self) 
        # setGeometry(x_pos, y_pos, width, height) 
        self.setGeometry(250, 150, 400, 300) 
        self.setWindowTitle("explore QTabWidget()")         
         
        tab_widget = QTabWidget() 
        tab1 = QWidget() 
        tab2 = QWidget() 
         
        tab_widget.addTab(tab1, "page1") 
        tab_widget.addTab(tab2, "page2")
        
        # put a button on tab1 (page1)
        btn_hello1 = QPushButton("Hello page1", tab1)
        btn_hello1.move(10, 10)
        # put a button on tab2 (page2)
        btn_hello2 = QPushButton("Hello page2", tab2)
        btn_hello2.move(10, 10)

        # layout manager
        vbox = QVBoxLayout()
        vbox.addWidget(tab_widget)         
        self.setLayout(vbox)      

        # optionally create layout for each page
        p1_vbox = QVBoxLayout(tab1)
        #p1_vbox.addWidget(btn_hello1) 
        p2_vbox = QVBoxLayout(tab2)
        
        
app = QApplication([]) 
frame = MainWindow() 
frame.show() 
app.exec_()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.