PyQt

Thread Solved

Join Date: Aug 2008
Posts: 19
Reputation: OutOfReach is an unknown quantity at this point 
Solved Threads: 2
OutOfReach OutOfReach is offline Offline
Newbie Poster

PyQt

 
0
  #1
Aug 21st, 2008
Hello guys.
I am having trouble with QTabWidget:
I can't add multiple widgets with addTab nor insertTab.
even when I try something like:
  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?
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,202
Reputation: woooee is a jewel in the rough woooee is a jewel in the rough woooee is a jewel in the rough woooee is a jewel in the rough 
Solved Threads: 341
woooee woooee is offline Offline
Nearly a Posting Virtuoso

Re: PyQt

 
0
  #2
Aug 21st, 2008
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.
  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()
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 19
Reputation: OutOfReach is an unknown quantity at this point 
Solved Threads: 2
OutOfReach OutOfReach is offline Offline
Newbie Poster

Re: PyQt

 
0
  #3
Aug 21st, 2008
Yes I am using classes, here is some more information:
Here is a snippet of the code that I am having trouble with:
  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:
  1. self.tabs.addTab(self.layout, "Create Tab")
  2. TypeError: argument 1 of QTabWidget.addTab() has an invalid type.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,202
Reputation: woooee is a jewel in the rough woooee is a jewel in the rough woooee is a jewel in the rough woooee is a jewel in the rough 
Solved Threads: 341
woooee woooee is offline Offline
Nearly a Posting Virtuoso

Re: PyQt

 
0
  #4
Aug 21st, 2008
I'm still using qt3, but it should be somewhere in the vicinity of this
  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 10:17 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 19
Reputation: OutOfReach is an unknown quantity at this point 
Solved Threads: 2
OutOfReach OutOfReach is offline Offline
Newbie Poster

Re: PyQt

 
0
  #5
Aug 22nd, 2008
That works for one widget, but what I am trying to achieve is to add multiple widgets to the same tab.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,202
Reputation: woooee is a jewel in the rough woooee is a jewel in the rough woooee is a jewel in the rough woooee is a jewel in the rough 
Solved Threads: 341
woooee woooee is offline Offline
Nearly a Posting Virtuoso

Re: PyQt

 
0
  #6
Aug 22nd, 2008
I will only give you a hint since the answer is obvious. The variable is named self.tab_1.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 19
Reputation: OutOfReach is an unknown quantity at this point 
Solved Threads: 2
OutOfReach OutOfReach is offline Offline
Newbie Poster

Re: PyQt

 
0
  #7
Aug 22nd, 2008
I don't really understand
I tried that with a layout but it didn't work
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 19
Reputation: OutOfReach is an unknown quantity at this point 
Solved Threads: 2
OutOfReach OutOfReach is offline Offline
Newbie Poster

Re: PyQt

 
0
  #8
Aug 22nd, 2008
I am dumb.
It was right there infront of my eyes!
Thank you!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum


Views: 2856 | Replies: 7
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC