Foros del Web » Programando para Internet » Python »

Layout en PyQt4

Estas en el tema de Layout en PyQt4 en el foro de Python en Foros del Web. @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código Python: Ver original #!/usr/bin/env python # -*- coding: utf-8 -*-   import sys from PyQt4. QtCore import SIGNAL from PyQt4. QtGui import ...
  #1 (permalink)  
Antiguo 27/09/2012, 19:14
 
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"
  #2 (permalink)  
Antiguo 28/09/2012, 08:06
AlvaroG
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Layout en PyQt4

Como no estás detallando cuál es el problema, solamente puedo recomendarte que leas la documentación y llegado el caso utilices un diseñador de interfaces como QtDesigner para evitarte problemas.


Saludos.

Etiquetas: gui, layout, pyqt4
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 17:27.