Ver Mensaje Individual
  #1 (permalink)  
Antiguo 27/09/2012, 19:14
AlanFC
 
Fecha de Ingreso: septiembre-2011
Mensajes: 42
Antigüedad: 12 años, 7 meses
Puntos: 3
Layout en PyQt4

Código Python:
Ver original
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import sys
  5. from PyQt4.QtCore import SIGNAL
  6. from PyQt4.QtGui import QLabel, QWidget, QLineEdit, QApplication, QHBoxLayout, QVBoxLayout, QPushButton, QMainWindow, QAction
  7.  
  8. class MyMainWindow(QMainWindow):
  9.     def __init__(self, parent = None):
  10.         QMainWindow.__init__(self, parent)
  11.  
  12.         self.setWindowTitle("Buscador")
  13.         self.statusBar().showMessage("Esperando datos...")
  14.         if True:
  15.             self.centralWidget = MyWidget()
  16.         else:
  17.             centralWidget = QLabel("OK")
  18.         self.setCentralWidget(self.centralWidget)
  19. class MyWidget(QWidget):
  20.     def __init__(self, parent = None):
  21.         QWidget.__init__(self, parent)
  22.  
  23.         layoutLabel = QVBoxLayout(self)
  24.         label1 = QLabel("Usuario")
  25.         label2 = QLabel(u"Contraseña")
  26.         label1.setToolTip("Usuario")
  27.         label2.setToolTip(u"Contraseña")
  28.         layoutLabel.addWidget(label1)
  29.         layoutLabel.addWidget(label2)
  30.  
  31.         layoutEntry = QVBoxLayout(self)
  32.         self.entry1 = QLineEdit()
  33.         self.entry2 = QLineEdit()
  34.         self.entry1.setToolTip("Ingrese usuario")
  35.         self.entry2.setToolTip(u"Ingrese contraseña")
  36.         layoutEntry.addWidget(self.entry1)
  37.         layoutEntry.addWidget(self.entry2)
  38.  
  39.         layoutData = QHBoxLayout(self)
  40.         layoutData.addStretch(1)
  41.         print "hola"
  42.         layoutData.addLayout(layoutLabel)
  43.         layoutData.addLayout(layoutEntry)
  44.  
  45.         layoutEnd = QVBoxLayout(self)
  46.         button = QPushButton("Conectar")
  47.         button.setToolTip("Presionar para conectar")
  48.         self.connect(button, SIGNAL("clicked()"), self.conectar)
  49.         layoutEnd.addStretch(1)
  50.         layoutEnd.addLayout(layoutData)
  51.         layoutEnd.addWidget(button)
  52.  
  53.     def conectar(self):
  54.         self.user = self.entry1.text()
  55.         self.passw = self.entry2.text()
  56.         print self.user
  57.  
  58. app = QApplication(sys.argv)
  59. windows = MyMainWindow()
  60. windows.show()
  61. app.exec_()

Cual es la forma correcta de trabajar con esos Layout?
Inicialmente tenia otro codigo, tenia varias clases (MyLabels, MyEntrys, MyData), donde en cada una tenia un Layout, entonces hiba agregandolos asi:

Código Python:
Ver original
  1. layoutData.addWidget(MyLabels)
  2. layoutData.addWidget(MyEntrys)

Me funcionaba bien, pero quiso borrar las 3, y quedarme solo con MyWidget, el problema es que no me funciona el mismo procedimiento, de agregar cada layout a uno mayor.

Que puedo hacer?
__________________
"Porque nada se...
quiero saberlo todo"