943,854 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 4901
  • Python RSS
Aug 21st, 2008
0

PyQt

Expand Post »
Hello guys.
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)
  1. self.widget1 = QListWidget()
  2. self.widget2 = QPushButton("Foo")
  3. self.widget3 = QLabel("Bar")
  4. self.tabs = QTabWidget()
  5. layout = QVBoxLayout()
  6. layout.addWidget(self.widget1)
  7. layout.addWidget(self.widget2)
  8. layout.addWidget(self.widget3)
  9. self.tabs.addTab(layout, "Foobar")

It will raise an error that the first argument (layout) is wrong. :/
Please, any help?
Similar Threads
Reputation Points: 10
Solved Threads: 2
Newbie Poster
OutOfReach is offline Offline
19 posts
since Aug 2008
Aug 21st, 2008
0

Re: PyQt

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)
  1. #****************************************************************************
  2. #** $Id: lineedits.py,v 1.1 2002/06/19 07:56:07 phil Exp $
  3. #**
  4. #** Copyright (C) 1992-1998 Troll Tech AS. All rights reserved.
  5. #**
  6. #** This file is part of an example program for PyQt. This example
  7. #** program may be used, distributed and modified without limitation.
  8. #**
  9. #*****************************************************************************/
  10.  
  11. import sys
  12. from qt import *
  13.  
  14. class LineEdits(QGroupBox):
  15. def __init__(self, parent = None, name = None):
  16. QGroupBox.__init__(self, 0, Qt.Horizontal, "Line Edits", parent, name)
  17.  
  18. self.setMargin(10)
  19.  
  20. vbox = QVBoxLayout(self.layout())
  21.  
  22. row1 = QHBoxLayout(vbox)
  23. row1.setMargin(5)
  24.  
  25. label = QLabel("Echo Mode: ", self)
  26. row1.addWidget(label)
  27.  
  28. combo1 = QComboBox(False, self)
  29. row1.addWidget(combo1)
  30. combo1.insertItem("Normal", -1)
  31. combo1.insertItem("Password", -1)
  32. combo1.insertItem("No Echo", -1)
  33.  
  34. self.connect(combo1, SIGNAL("activated(int)"), self.slotEchoChanged)
  35. self.lined1 = QLineEdit(self)
  36. vbox.addWidget(self.lined1)
  37.  
  38. row2 = QHBoxLayout(vbox)
  39. row2.setMargin(5)
  40.  
  41. label = QLabel("Validator: ", self)
  42. row2.addWidget(label)
  43.  
  44. combo2 = QComboBox(False, self)
  45. row2.addWidget(combo2)
  46. combo2.insertItem("No Validator", -1)
  47. combo2.insertItem("Integer Validator", -1)
  48. combo2.insertItem("Double Validator", -1)
  49.  
  50. self.connect(combo2, SIGNAL("activated(int)"), self.slotValidatorChanged)
  51.  
  52. self.lined2 = QLineEdit(self)
  53. vbox.addWidget(self.lined2)
  54.  
  55. row3 = QHBoxLayout(vbox)
  56. row3.setMargin(5)
  57.  
  58. label = QLabel("Alignment: ", self)
  59. row3.addWidget(label)
  60.  
  61. combo3 = QComboBox(False, self)
  62. row3.addWidget(combo3)
  63. combo3.insertItem("Left", -1)
  64. combo3.insertItem("Centered", -1)
  65. combo3.insertItem("Right", -1)
  66.  
  67. self.connect(combo3, SIGNAL("activated(int)"), self.slotAlignmentChanged)
  68. self.lined3 = QLineEdit(self)
  69. vbox.addWidget(self.lined3)
  70.  
  71. row4 = QHBox(self)
  72. vbox.addWidget(row4)
  73. row4.setMargin(5)
  74.  
  75. QLabel("Read-Only: ", row4)
  76.  
  77. combo4 = QComboBox(True, row4)
  78. combo4.insertItem("False", -1)
  79. combo4.insertItem("True", -1)
  80.  
  81. self.connect(combo4, SIGNAL("activated(int)"), self.slotReadOnlyChanged)
  82.  
  83. self.lined4 = QLineEdit(self)
  84. vbox.addWidget(self.lined4)
  85.  
  86. self.lined1.setFocus()
  87.  
  88. def slotEchoChanged(self, i):
  89. if i == 0:
  90. self.lined1.setEchoMode(QLineEdit.Normal)
  91. elif i == 1:
  92. self.lined1.setEchoMode(QLineEdit.Password)
  93. elif i == 2:
  94. self.lined1.setEchoMode(QLineEdit.NoEcho)
  95.  
  96. self.lined1.setFocus()
  97.  
  98. def slotValidatorChanged(self, i):
  99. if i == 0:
  100. self.lined2.setValidator(None)
  101. elif i == 1:
  102. self.lined2.setValidator(QIntValidator(self.lined2))
  103. elif i == 2:
  104. self.lined2.setValidator(QDoubleValidator(-999.0, 999.0, 2, self.lined2))
  105.  
  106. self.lined2.setText("")
  107. self.lined2.setFocus()
  108.  
  109. def slotAlignmentChanged(self, i):
  110. if i == 0:
  111. self.lined3.setAlignment(QLineEdit.AlignLeft)
  112. elif i == 1:
  113. self.lined3.setAlignment(QLineEdit.AlignCenter)
  114. elif i == 2:
  115. self.lined3.setAlignment(QLineEdit.AlignRight)
  116.  
  117. self.lined3.setFocus()
  118.  
  119. def slotReadOnlyChanged(self, i):
  120. if i == 0:
  121. self.lined4.setReadOnly(FALSE)
  122. elif i == 1:
  123. self.lined4.setReadOnly(TRUE)
  124.  
  125. self.lined4.setFocus()
  126.  
  127.  
  128. if __name__=='__main__':
  129. app = QApplication( sys.argv )
  130.  
  131. lineedits = LineEdits()
  132. lineedits.setCaption("Lineedits - PyQt Example")
  133. lineedits.show()
  134. app.setMainWidget(lineedits)
  135. app.exec_loop()
Reputation Points: 741
Solved Threads: 692
Nearly a Posting Maven
woooee is offline Offline
2,305 posts
since Dec 2006
Aug 21st, 2008
0

Re: PyQt

Yes I am using classes, here is some more information:
Here is a snippet of the code that I am having trouble with:
Python Syntax (Toggle Plain Text)
  1. import sys
  2. import os
  3. from PyQt4.QtCore import *
  4. from PyQt4.QtGui import *
  5.  
  6. class PyQtFrontend(QDialog):
  7.  
  8. def __init__(self, rp,parent=None):
  9. super(PyQtFrontend, self).__init__(parent)
  10.  
  11. """Initialize our widgets."""
  12.  
  13.  
  14. self.tabs = QTabWidget()
  15. self.rpNameLabel = QLabel("Name:")
  16. self.rpName = QLineEdit("default")
  17. self.rpName.selectAll()
  18.  
  19. self.createPointButton = QPushButton("Create")
  20.  
  21.  
  22. self.layout = QVBoxLayout()
  23. self.layout.addWidget(self.rpNameLabel)
  24. self.layout.addWidget(self.rpName)
  25. self.layout.addWidget(self.createPointButton)
  26. self.tabs.addTab(self.layout, "Create Tab")

And here's the exception that gets thrown:
Python Syntax (Toggle Plain Text)
  1. self.tabs.addTab(self.layout, "Create Tab")
  2. TypeError: argument 1 of QTabWidget.addTab() has an invalid type.
Reputation Points: 10
Solved Threads: 2
Newbie Poster
OutOfReach is offline Offline
19 posts
since Aug 2008
Aug 21st, 2008
0

Re: PyQt

I'm still using qt3, but it should be somewhere in the vicinity of this
Python Syntax (Toggle Plain Text)
  1. self.tab_1 = QWidget()
  2. self.tab_1.setObjectName("Create Tab")
  3. self.tabs.addTab(self.tab_1, "")
  4. self.layout.addWidget(self.tabs)
Last edited by woooee; Aug 21st, 2008 at 11:17 pm.
Reputation Points: 741
Solved Threads: 692
Nearly a Posting Maven
woooee is offline Offline
2,305 posts
since Dec 2006
Aug 22nd, 2008
0

Re: PyQt

That works for one widget, but what I am trying to achieve is to add multiple widgets to the same tab.
Reputation Points: 10
Solved Threads: 2
Newbie Poster
OutOfReach is offline Offline
19 posts
since Aug 2008
Aug 22nd, 2008
0

Re: PyQt

I will only give you a hint since the answer is obvious. The variable is named self.tab_1.
Reputation Points: 741
Solved Threads: 692
Nearly a Posting Maven
woooee is offline Offline
2,305 posts
since Dec 2006
Aug 22nd, 2008
0

Re: PyQt

I don't really understand
I tried that with a layout but it didn't work
Reputation Points: 10
Solved Threads: 2
Newbie Poster
OutOfReach is offline Offline
19 posts
since Aug 2008
Aug 22nd, 2008
0

Re: PyQt

I am dumb.
It was right there infront of my eyes!
Thank you!
Reputation Points: 10
Solved Threads: 2
Newbie Poster
OutOfReach is offline Offline
19 posts
since Aug 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: GIS + Python: Lists and Sublists (?)
Next Thread in Python Forum Timeline: Problem with BLOB Insert to MySQL using ODBC





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC