Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anterior Revisión previa Próxima revisión | Revisión previa | ||
|
fw:pyqt4 [2010/07/03 19:09] alfred |
fw:pyqt4 [2020/05/09 09:25] (actual) |
||
|---|---|---|---|
| Línea 146: | Línea 146: | ||
| print 'Too Much: ' + str(v) | print 'Too Much: ' + str(v) | ||
| </code> | </code> | ||
| + | |||
| + | |||
| Línea 170: | Línea 172: | ||
| * **QVBoxLayout**: Donde los elementos se muestran en vertical. | * **QVBoxLayout**: Donde los elementos se muestran en vertical. | ||
| * **QHBoxLayout**: Donde los elementos se muestran en horizontal. | * **QHBoxLayout**: Donde los elementos se muestran en horizontal. | ||
| - | * **QGridLayout** | + | * **QGridLayout**: Donde los elementos se colocan en una tabla (con 'x' e 'y'). |
| + | <code python> | ||
| + | self.grid = QtGui.QGridLayout() | ||
| + | self.setLayout(self.grid) | ||
| + | self.grid.addWidget(QtGui.QLabel("HOLA"), 0, 0) | ||
| + | self.grid.addWidget(QtGui.QLabel("ADIOS"), 1, 1) | ||
| + | self.grid.addWidget(QtGui.QLabel("ARREVOIRE"), 2, 2) | ||
| + | self.grid.addWidget(QtGui.QLabel("Yey!"), 2, 0) | ||
| + | </code> | ||
| Línea 193: | Línea 203: | ||
| === Qt Style Sheets === | === Qt Style Sheets === | ||
| + | Las Qt Style Seets son otra forma de personalizar la apariencia de los widgets y están basadas en las CSS ([[http://doc.qt.nokia.com/4.6/stylesheet-reference.html|referencia]]). | ||
| <code python> | <code python> | ||
| self.setStyleSheet("QWidget { background-color: rgb(255, 255, 255); background-image: url(heart.png); border-top:5px solid rgb(255, 170, 255); }") | self.setStyleSheet("QWidget { background-color: rgb(255, 255, 255); background-image: url(heart.png); border-top:5px solid rgb(255, 170, 255); }") | ||
| + | </code> | ||
| + | Pueden ser definidas.. | ||
| + | <code> | ||
| + | QComboBox { | ||
| + | margin-right: 20px; | ||
| + | } | ||
| + | QComboBox::drop-down { | ||
| + | subcontrol-origin: margin; | ||
| + | } | ||
| + | QComboBox::down-arrow { | ||
| + | image: url(down_arrow.png); | ||
| + | } | ||
| + | QComboBox::down-arrow:pressed { | ||
| + | position: relative; | ||
| + | top: 1px; left: 1px; | ||
| + | } | ||
| </code> | </code> | ||
| Línea 209: | Línea 236: | ||
| ===== Creación avanzada de aplicaciones ===== | ===== Creación avanzada de aplicaciones ===== | ||
| + | |||
| + | |||
| Línea 240: | Línea 269: | ||
| === La clase QImage === | === La clase QImage === | ||
| + | Podemos obtener imágenes escaladas a partir de su método ''scaled'': | ||
| + | <code python> | ||
| + | image = QImage("/path/to/image") | ||
| + | thumbnail1 = image.scaled(10, 10) | ||
| + | </code> | ||
| Podemos pintar sobre una QImage con el QPainter: | Podemos pintar sobre una QImage con el QPainter: | ||
| <code python> | <code python> | ||
| Línea 264: | Línea 297: | ||
| </code> | </code> | ||
| + | * Podemos, también, descargar una imágen y mostrarla: | ||
| + | <code python> | ||
| + | class MyWindow(QtGui.QWidget): | ||
| + | def __init__(self): | ||
| + | QtGui.QWidget.__init__(self) | ||
| + | self.lbl = QtGui.QLabel(self) | ||
| + | self.url = QtNetwork.QHttp() | ||
| + | self.url.done.connect(self.showImage) | ||
| + | self.url.setHost('sonfamosos.com') | ||
| + | self.url.get('/wp-content/uploads/2009/12/hulk-hogan.jpg') | ||
| + | | ||
| + | def showImage(self): | ||
| + | img = QtGui.QImage.fromData(self.url.readAll(), 'JPG') | ||
| + | self.lbl.setPixmap(QtGui.QPixmap.fromImage(img)) | ||
| + | self.lbl.resize(img.width(), img.height()) | ||
| + | </code> | ||
| ===== Otros módulos en PyQt ===== | ===== Otros módulos en PyQt ===== | ||