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 19:06]
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 =====
 +
 +
 +
 +
 +
  
  
Línea 230: Línea 269:
  
 === La clase QImage === === La clase QImage ===
- +Podemos obtener imágenes escaladas a partir de su método ''​scaled''​:
- +
-=== Pintar sobre QImage === +
-También podemos pintar sobre una QImage con el QPainter:+
 <code python> <code python>
-    ​def paintEvent(self,​ event): +image = QImage("/​path/​to/​image"​) 
-        i = QtGui.QImage(event.rect().width(),​ event.rect().height(),​ QtGui.QImage.Format_ARGB32) +thumbnail1 = image.scaled(10,​ 10) 
-        ipaint = QtGui.QPainter() +</​code>​ 
-        ipaint.begin(i) +Podemos pintar sobre una QImage con el QPainter: 
-        ipaint.drawImage(event.rect(),​ QtGui.QImage("​heart.png"​)) +<code python>​ 
-        ipaint.end()+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 = QtGui.QPainter() 
-        paint.begin(self) ​        +   ​paint.begin(self) ​        
-        paint.drawImage(event.rect(),​ i); +   ​paint.drawImage(event.rect(),​ i); 
-        paint.end()+   ​paint.end()
 </​code>​ </​code>​
  
Línea 256: Línea 297:
 </​code>​ </​code>​
  
-==== Qt Style Sheets ====+  * 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.1278183979.txt.gz · Última modificación: 2020/05/09 09:24 (editor externo)