Herramientas de usuario

Herramientas del sitio


fw:pyqt4

Diferencias

Muestra las diferencias entre dos versiones de la página.

Enlace a la vista de comparación

Ambos lados, revisión anterior Revisión previa
Próxima revisión
Revisión previa
fw:pyqt4 [2010/07/03 18:57]
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 169: 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 189: Línea 200:
     def btnClick (self):     def btnClick (self):
         print "​a"​         print "​a"​
 +</​code>​
 +
 +=== 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>
 +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 202: Línea 236:
  
 ===== Creación avanzada de aplicaciones ===== ===== Creación avanzada de aplicaciones =====
 +
 +
 +
 +
 +
 +
  
  
 ==== Paint & QImages ==== ==== Paint & QImages ====
 +
 === Pintar sobre QWidgets === === Pintar sobre QWidgets ===
 Para poder pintar sobre un QWidget lo haremos sobreescribiendo el método ''​paintEvent''​ de este y mediante los métodos de un objeto **QPainter**,​ lo crearemos y luego, entre sus los métodos ''​begin''​ (al cual le tendremos que pasar el QWidget sobre el cual pintaremos) y ''​end''​ llevaremos a cabo los métodos de pintar: Para poder pintar sobre un QWidget lo haremos sobreescribiendo el método ''​paintEvent''​ de este y mediante los métodos de un objeto **QPainter**,​ lo crearemos y luego, entre sus los métodos ''​begin''​ (al cual le tendremos que pasar el QWidget sobre el cual pintaremos) y ''​end''​ llevaremos a cabo los métodos de pintar:
Línea 228: 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:
 +<code python>
 +def paintEvent(self,​ event):
 +   i = QtGui.QImage(event.rect().width(),​ event.rect().height(),​ QtGui.QImage.Format_ARGB32)
 +   ​ipaint = QtGui.QPainter()
 +   ​ipaint.begin(i)
 +   ​ipaint.drawImage(event.rect(),​ QtGui.QImage("​heart.png"​))
 +   ​ipaint.end()
  
 +   paint = QtGui.QPainter()
 +   ​paint.begin(self) ​       ​
 +   ​paint.drawImage(event.rect(),​ i);
 +   ​paint.end()
 +</​code>​
  
-=== Pintar ​sobre QImage ​=== +=== Notas sobre imágenes ​=== 
-También podemos pintar sobre una QImage con el QPainter:+  * Podemos mostrar imágenes a partir de QLabels asignando su propiedad ''​PixMap''​:
 <code python> <code python>
-    def paintEvent(self, event): +self.lbl = QtGui.QLabel(self
-        i = QtGui.QImage(event.rect().width(),​ event.rect().height(),​ QtGui.QImage.Format_ARGB32+qPixMap ​= QtGui.QPixmap.fromImage(QtGui.QImage("​heart.png"​)) 
-        ​ipaint ​= QtGui.QPainter() +self.lbl.setPixmap(qPixMap)
-        ipaint.begin(i) +
-        ipaint.drawImage(event.rect(), ​QtGui.QImage("​heart.png"​)) +
-        ​ipaint.end() +
- +
-        paint = QtGui.QPainter() +
-        paint.begin(self)         +
-        paint.drawImage(event.rect(),​ i); +
-        paint.end()+
 </​code>​ </​code>​
  
-==== Estilos ====+  * Podemos, también, descargar una imágen y mostrarla:
 <code python> <code python>
-self.setStyleSheet("QWidget ​{ background-colorrgb(255, 255, 255); background-image: url(heart.png); border-top:5px solid rgb(255170255); }")+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>​ </​code>​
 +
 +===== Otros módulos en PyQt =====
 +
fw/pyqt4.1278183442.txt.gz · Última modificación: 2020/05/09 09:24 (editor externo)