Hello guys.
I am having trouble with QTabWidget:
I can't add multiple widgets with addTab nor insertTab.
even when I try something like:

self.widget1 = QListWidget()
self.widget2 = QPushButton("Foo")
self.widget3 = QLabel("Bar")
self.tabs = QTabWidget()
layout = QVBoxLayout()
layout.addWidget(self.widget1)
layout.addWidget(self.widget2)
layout.addWidget(self.widget3)
self.tabs.addTab(layout, "Foobar")

It will raise an error that the first argument (layout) is wrong. :/
Please, any help?

There is not enough code here or enough of the error message to help you. If you are not using a class,

the "self." will yield errors. This is an example using QVBoxLayout that hopefully will help.

#****************************************************************************
#** $Id: lineedits.py,v 1.1 2002/06/19 07:56:07 phil Exp $
#**
#** Copyright (C) 1992-1998 Troll Tech AS.  All rights reserved.
#**
#** This file is part of an example program for PyQt.  This example
#** program may be used, distributed and modified without limitation.
#**
#*****************************************************************************/

import sys
from qt import *

class LineEdits(QGroupBox):
    def __init__(self, parent = None, name = None):
        QGroupBox.__init__(self, 0, Qt.Horizontal, "Line Edits", parent, name)

        self.setMargin(10)
        
        vbox = QVBoxLayout(self.layout())
        
        row1 = QHBoxLayout(vbox)
        row1.setMargin(5)

        label = QLabel("Echo Mode: ", self)
        row1.addWidget(label)

        combo1 = QComboBox(False, self) 
        row1.addWidget(combo1)
        combo1.insertItem("Normal", -1) 
        combo1.insertItem("Password", -1) 
        combo1.insertItem("No Echo", -1)

        self.connect(combo1, SIGNAL("activated(int)"), self.slotEchoChanged)
        self.lined1 = QLineEdit(self)
        vbox.addWidget(self.lined1)

        row2 = QHBoxLayout(vbox)
        row2.setMargin(5)

        label = QLabel("Validator: ", self)
        row2.addWidget(label)

        combo2 = QComboBox(False, self)
        row2.addWidget(combo2)
        combo2.insertItem("No Validator", -1)
        combo2.insertItem("Integer Validator", -1)
        combo2.insertItem("Double Validator", -1)
        
        self.connect(combo2, SIGNAL("activated(int)"), self.slotValidatorChanged)

        self.lined2 = QLineEdit(self)
        vbox.addWidget(self.lined2)

        row3 = QHBoxLayout(vbox)
        row3.setMargin(5)

        label = QLabel("Alignment: ", self)
        row3.addWidget(label)

        combo3 = QComboBox(False, self)
        row3.addWidget(combo3)
        combo3.insertItem("Left", -1)
        combo3.insertItem("Centered", -1)
        combo3.insertItem("Right", -1)

        self.connect(combo3, SIGNAL("activated(int)"), self.slotAlignmentChanged)
        self.lined3 = QLineEdit(self)
        vbox.addWidget(self.lined3)

        row4 = QHBox(self)
        vbox.addWidget(row4)
        row4.setMargin(5)

        QLabel("Read-Only: ", row4)

        combo4 = QComboBox(True, row4)
        combo4.insertItem("False", -1)
        combo4.insertItem("True", -1)

        self.connect(combo4, SIGNAL("activated(int)"), self.slotReadOnlyChanged)

        self.lined4 = QLineEdit(self)
        vbox.addWidget(self.lined4)

        self.lined1.setFocus()

    def slotEchoChanged(self, i):
        if i == 0:
            self.lined1.setEchoMode(QLineEdit.Normal)
        elif i == 1:
            self.lined1.setEchoMode(QLineEdit.Password)
        elif i == 2:
            self.lined1.setEchoMode(QLineEdit.NoEcho)

        self.lined1.setFocus()

    def slotValidatorChanged(self, i):
        if i == 0:
            self.lined2.setValidator(None)
        elif i == 1:
            self.lined2.setValidator(QIntValidator(self.lined2))
        elif i == 2:
            self.lined2.setValidator(QDoubleValidator(-999.0, 999.0, 2, self.lined2))

        self.lined2.setText("")
        self.lined2.setFocus()

    def slotAlignmentChanged(self, i):
        if i == 0:
            self.lined3.setAlignment(QLineEdit.AlignLeft)
        elif i == 1:
            self.lined3.setAlignment(QLineEdit.AlignCenter)
        elif i == 2:
            self.lined3.setAlignment(QLineEdit.AlignRight)

        self.lined3.setFocus()

    def slotReadOnlyChanged(self, i):
        if i == 0:
            self.lined4.setReadOnly(FALSE)
        elif i == 1:
            self.lined4.setReadOnly(TRUE)

        self.lined4.setFocus()


if __name__=='__main__':
    app = QApplication( sys.argv )

    lineedits = LineEdits()
    lineedits.setCaption("Lineedits - PyQt Example")
    lineedits.show()
    app.setMainWidget(lineedits)
    app.exec_loop()

Yes I am using classes, here is some more information:
Here is a snippet of the code that I am having trouble with:

import sys
import os
from PyQt4.QtCore import *
from PyQt4.QtGui import *

class PyQtFrontend(QDialog):

    def __init__(self, rp,parent=None):
        super(PyQtFrontend, self).__init__(parent)

        """Initialize our widgets."""


        self.tabs = QTabWidget()
        self.rpNameLabel = QLabel("Name:")
        self.rpName = QLineEdit("default")
        self.rpName.selectAll()

        self.createPointButton = QPushButton("Create")


        self.layout = QVBoxLayout()
        self.layout.addWidget(self.rpNameLabel)
        self.layout.addWidget(self.rpName)
        self.layout.addWidget(self.createPointButton)
        self.tabs.addTab(self.layout, "Create Tab")

And here's the exception that gets thrown:

self.tabs.addTab(self.layout, "Create Tab")
TypeError: argument 1 of QTabWidget.addTab() has an invalid type.

I'm still using qt3, but it should be somewhere in the vicinity of this

self.tab_1 = QWidget()
        self.tab_1.setObjectName("Create Tab")
        self.tabs.addTab(self.tab_1, "")
        self.layout.addWidget(self.tabs)

That works for one widget, but what I am trying to achieve is to add multiple widgets to the same tab.

I will only give you a hint since the answer is obvious. The variable is named self.tab_1.

I don't really understand :|
I tried that with a layout but it didn't work :$

I am dumb.
It was right there infront of my eyes!
Thank you! :)

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.