Hi I am attempting to make Quicktime player like control bar shown belowScreen Shot 2013-12-28 at 10.43.01 AM.png

However I was also attempting to make round buttons, but neither round buttons nor the quicktime like just the icon on button seems to work,

Here is the code, I guess it will be useful for anyone , Please tell me how can I make quicktime player like control bar

also a thin black line is showing up around the window and the buttons what is causing that and how can I get rid of it ?

Qt Code:
  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.4, QtCore.Qt.black)
  80. btnGradient.setColorAt(0.5, QtCore.Qt.white)
  81. btnGradient.setColorAt(0.5, QtCore.Qt.gray)
  82. btnGradient.setColorAt(0.4, QtCore.Qt.white)
  83. btnGradient.setColorAt(0.2, QtCore.Qt.gray)
  84. btnPaint.setBrush(btnGradient)
  85. # btnPaint.drawEllipse(10,10,self.width()-10, self.height())
  86. btnPaint.drawRoundedRect(10, 2, self.width()-12, self.height()-6, 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_())
To copy to clipboard, switch view to plain text mode