| | |
PyQt
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Aug 2008
Posts: 19
Reputation:
Solved Threads: 2
Hello guys.
I am having trouble with QTabWidget:
I can't add multiple widgets with addTab nor insertTab.
even when I try something like:
It will raise an error that the first argument (layout) is wrong. :/
Please, any help?
I am having trouble with QTabWidget:
I can't add multiple widgets with addTab nor insertTab.
even when I try something like:
python Syntax (Toggle Plain Text)
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?
•
•
Join Date: Dec 2006
Posts: 1,045
Reputation:
Solved Threads: 294
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.
Python Syntax (Toggle Plain Text)
#**************************************************************************** #** $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()
•
•
Join Date: Aug 2008
Posts: 19
Reputation:
Solved Threads: 2
Yes I am using classes, here is some more information:
Here is a snippet of the code that I am having trouble with:
And here's the exception that gets thrown:
Here is a snippet of the code that I am having trouble with:
Python Syntax (Toggle Plain Text)
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:
Python Syntax (Toggle Plain Text)
self.tabs.addTab(self.layout, "Create Tab") TypeError: argument 1 of QTabWidget.addTab() has an invalid type.
•
•
Join Date: Dec 2006
Posts: 1,045
Reputation:
Solved Threads: 294
I'm still using qt3, but it should be somewhere in the vicinity of this
Python Syntax (Toggle Plain Text)
self.tab_1 = QWidget() self.tab_1.setObjectName("Create Tab") self.tabs.addTab(self.tab_1, "") self.layout.addWidget(self.tabs)
Last edited by woooee; Aug 21st, 2008 at 11:17 pm.
![]() |
Similar Threads
- Pyqt and gif (Python)
- learn pyqt (Python)
- While loop problem in pyqt (Python)
- learn pyqt (Python)
- Newbie (C++)
Other Threads in the Python Forum
- Previous Thread: GIS + Python: Lists and Sublists (?)
- Next Thread: Problem with BLOB Insert to MySQL using ODBC
| Thread Tools | Search this Thread |
Tag cloud for Python
accessdenied advanced application argv beginner change code color command csv def dictionary dynamic edit editing enter event examples excel file float format function google gui homework import inches input jaunty java keyboard lapse line linux list lists loop microphone mouse movingimageswithpygame mysql newb number numbers numeric obexftp output parameters parsing path port prime programming projects py2exe pygame pygtk pyopengl pyqt python random recursion remote return reverse scrolledtext session simple skinning smtp software sprite statictext stderr string strings strip syntax table tennis terminal text thread threading time tkinter tlapse trick tuple tutorial ubuntu unicode unit urllib urllib2 variable voip windows wxpython







