Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PyQt4 import QtGui, QtCore
- import sys
- class ControlBar(QtGui.QWidget):
- """ docstring for ControlBar"""
- def __init__(self, parent=None):
- super(ControlBar, self).__init__(parent)
- self.resize(440, 100)
- self.setStyleSheet("""
- QWidget{
- opacity: 50;
- }
- """)
- self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
- self.setWindowTitle("QLinearGradient Vertical Gradient ")
- self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
- self.buildUi()
- def mousePressEvent(self, event):
- self.offset = event.pos()
- def mouseMoveEvent(self, event):
- try:
- x=event.globalX()
- y=event.globalY()
- x_w = self.offset.x()
- y_w = self.offset.y()
- self.move(x-x_w, y-y_w)
- except: pass
- def paintEvent(self, ev):
- painter = QtGui.QPainter(self)
- gradient = QtGui.QLinearGradient(QtCore.QRectF(self.rect()).topLeft(),QtCore.QRectF(self.rect()).bottomLeft())
- gradient.setColorAt(0.0, QtCore.Qt.black)
- gradient.setColorAt(0.4, QtCore.Qt.gray)
- gradient.setColorAt(0.7, QtCore.Qt.black)
- painter.setBrush(gradient)
- self.openBtn.clicked.connect(self.testMessage)
- self.backBtn.clicked.connect(self.closeMe)
- painter.drawRoundedRect(0, 0, 440, 100, 20.0, 20.0)
- def buildUi(self):
- self.hoelayout = QtGui.QHBoxLayout()
- self.openBtn = RoundEdgeButton("Hello")
- self.backBtn = RoundEdgeButton()
- self.pausBtn = RoundEdgeButton()
- self.nextBtn = RoundEdgeButton()
- self.hoelayout.addStretch(1)
- self.hoelayout.addWidget(self.openBtn)
- self.hoelayout.addStretch(1)
- self.hoelayout.addWidget(self.backBtn)
- self.hoelayout.addStretch(1)
- self.hoelayout.addWidget(self.pausBtn)
- self.hoelayout.addStretch(1)
- self.hoelayout.addWidget(self.nextBtn)
- self.hoelayout.addStretch(1)
- self.setLayout(self.hoelayout)
- def closeMe(self):
- self.close()
- def testMessage(self):
- QtGui.QMessageBox.about(self, "Testing button pressed look feel", "just to check the pressed feel on button")
- class RoundEdgeButton(QtGui.QPushButton):
- """ docstring for RoundEdgeButton"""
- def __init__(self,text=None, parent=None):
- super(RoundEdgeButton, self).__init__(parent)
- if text:
- self.setText(text)
- # def sizeHint(self):
- # return QtCore.QSize(90,27)
- def paintEvent(self, ev):
- btnPaint = QtGui.QPainter(self)
- btnGradient = QtGui.QLinearGradient(QtCore.QRectF(self.rect()).topLeft(), QtCore.QRectF(self.rect()).bottomLeft())
- btnGradient.setColorAt(0.8, QtCore.Qt.black)
- btnGradient.setColorAt(0.1, QtCore.Qt.gray)
- btnGradient.setColorAt(0.8, QtCore.Qt.black)
- btnPaint.setBrush(btnGradient)
- # the round buttons show up oval
- # btnPaint.drawEllipse(10,10,self.width()-10, self.height())
- # the below one gets cut from right
- btnPaint.drawRoundedRect(10, 2, self.width(), self.height()*2, 10.0, 10.0)
- if __name__ == '__main__':
- app = QtGui.QApplication(sys.argv)
- win = ControlBar()
- win.show()
- win.raise_()
- sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement