Advertisement
sanfx

Quicktime_like_buttons.py

Dec 27th, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.92 KB | None | 0 0
  1. from PyQt4 import QtGui, QtCore
  2. import sys
  3.  
  4. class ControlBar(QtGui.QWidget):
  5.     """ docstring for ControlBar"""
  6.     def __init__(self, parent=None):
  7.         super(ControlBar, self).__init__(parent)
  8.         self.resize(440, 100)
  9.         self.setStyleSheet("""
  10.             QWidget{
  11.             opacity: 50;
  12.             }
  13.             """)
  14.         self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
  15.         self.setWindowTitle("QLinearGradient Vertical Gradient ")
  16.         self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
  17.         self.buildUi()
  18.  
  19.     def mousePressEvent(self, event):
  20.         self.offset = event.pos()
  21.  
  22.     def mouseMoveEvent(self, event):
  23.         try:
  24.               x=event.globalX()
  25.               y=event.globalY()
  26.               x_w = self.offset.x()
  27.               y_w = self.offset.y()
  28.               self.move(x-x_w, y-y_w)
  29.         except: pass  
  30.  
  31.     def paintEvent(self, ev):
  32.         painter = QtGui.QPainter(self)
  33.         gradient = QtGui.QLinearGradient(QtCore.QRectF(self.rect()).topLeft(),QtCore.QRectF(self.rect()).bottomLeft())
  34.         gradient.setColorAt(0.0, QtCore.Qt.black)
  35.         gradient.setColorAt(0.4, QtCore.Qt.gray)
  36.         gradient.setColorAt(0.7, QtCore.Qt.black)
  37.         painter.setBrush(gradient)
  38.         self.openBtn.clicked.connect(self.testMessage)
  39.         self.backBtn.clicked.connect(self.closeMe)
  40.         painter.drawRoundedRect(0, 0, 440, 100, 20.0, 20.0)
  41.        
  42.     def buildUi(self):
  43.         self.hoelayout = QtGui.QHBoxLayout()
  44.         self.openBtn = RoundEdgeButton("Hello")
  45.         self.backBtn = RoundEdgeButton()
  46.         self.pausBtn = RoundEdgeButton()
  47.         self.nextBtn = RoundEdgeButton()
  48.         self.hoelayout.addStretch(1)
  49.         self.hoelayout.addWidget(self.openBtn)
  50.         self.hoelayout.addStretch(1)
  51.         self.hoelayout.addWidget(self.backBtn)
  52.         self.hoelayout.addStretch(1)
  53.         self.hoelayout.addWidget(self.pausBtn)
  54.         self.hoelayout.addStretch(1)
  55.         self.hoelayout.addWidget(self.nextBtn)
  56.         self.hoelayout.addStretch(1)
  57.         self.setLayout(self.hoelayout)
  58.  
  59.     def closeMe(self):
  60.         self.close()
  61.  
  62.     def testMessage(self):
  63.         QtGui.QMessageBox.about(self, "Testing button pressed look feel", "just to check the pressed feel on button")
  64.  
  65. class RoundEdgeButton(QtGui.QPushButton):
  66.     """ docstring for RoundEdgeButton"""
  67.     def __init__(self,text=None, parent=None):
  68.         super(RoundEdgeButton, self).__init__(parent)
  69.  
  70.         if text:
  71.             self.setText(text)
  72.  
  73.     # def sizeHint(self):
  74.     #   return QtCore.QSize(90,27)
  75.  
  76.     def paintEvent(self, ev):
  77.         btnPaint = QtGui.QPainter(self)
  78.         btnGradient = QtGui.QLinearGradient(QtCore.QRectF(self.rect()).topLeft(), QtCore.QRectF(self.rect()).bottomLeft())
  79.         btnGradient.setColorAt(0.8, QtCore.Qt.black)
  80.         btnGradient.setColorAt(0.1, QtCore.Qt.gray)
  81.         btnGradient.setColorAt(0.8, QtCore.Qt.black)
  82.         btnPaint.setBrush(btnGradient)
  83.         # the round buttons show up oval
  84.         # btnPaint.drawEllipse(10,10,self.width()-10, self.height())
  85.         # the below one gets cut from right
  86.         btnPaint.drawRoundedRect(10, 2, self.width(), self.height()*2, 10.0, 10.0)
  87.        
  88.  
  89. if __name__ == '__main__':
  90.     app = QtGui.QApplication(sys.argv)
  91.     win = ControlBar()
  92.     win.show()
  93.     win.raise_()
  94.     sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement