Advertisement
Guest User

round corners

a guest
Apr 9th, 2012
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.74 KB | None | 0 0
  1. picture = "snap.png"
  2. if os.path.isfile(picture):
  3.     scaledpicture = QtGui.QPixmap(picture).scaled(238, 174, QtCore.Qt.IgnoreAspectRatio, QtCore.Qt.FastTransformation)
  4.     pixlabel = QtGui.QLabel()
  5.     pixlabel.setPixmap(scaledpicture)
  6.     pixlabel.setStyleSheet("border:2px solid grey; border-radius: 10px;background-color: transparent;");
  7.     picitem = QtGui.QGraphicsPixmapItem(pixlabel.pixmap())
  8.     picitem.setPos((260 * col), lin)
  9.     self.scene.addItem(picitem)
  10.  
  11. ------------------------------------
  12.  
  13. picture = "snap.png"
  14. if os.path.isfile(picture):
  15.     pixlabel = QtGui.QLabel()
  16.     pixlabel.setPixmap(scaledpicture)
  17.     pixlabel.setMask(scaledpicture.mask())
  18.     pixlabel.setFixedSize(scaledpicture.width(), scaledpicture.height())
  19.     pixlabel.setWindowFlags(QtCore.Qt.FramelessWindowHint)
  20.     pixlabel.move(100, 100)
  21.     picitem = QtGui.QGraphicsPixmapItem(pixlabel.pixmap())
  22.     picitem.setPos((260 * col), lin)
  23.     self.scene.addItem(picitem)
  24.    
  25. ------------------------------------
  26.  
  27. picture = "snap.png"
  28. if os.path.isfile(picture):
  29.     scaledpicture = QtGui.QPixmap(picture).scaled(238, 174, QtCore.Qt.IgnoreAspectRatio, QtCore.Qt.FastTransformation)
  30.     maskedpicture = maskregion(scaledpicture)
  31.     picitem = QtGui.QGraphicsPixmapItem(maskedpicture)
  32.     self.scene.addItem(picitem)
  33.    
  34. def maskregion(self, pixmap):
  35.     widget_rect = pixmap.rect()
  36.     painter = QtGui.QPainter(pixmap)
  37.     painter.save()
  38.     painter.setRenderHint(QtGui.QPainter.Antialiasing)
  39.     rounded_rect = QtGui.QPainterPath()
  40.     rounded_rect.addRoundedRect(1, 1, widget_rect.width() - 2, widget_rect.height() - 2, 20, 20, QtCore.Qt.AbsoluteSize)
  41.     painter.setClipPath(rounded_rect)
  42.     maskregion = painter.clipRegion()
  43.     return maskregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement