What I try is to customize the look and feel of my custom QRubberBand a bit. I want to achieve a blue selection edge with a transparent blue selection rectangle background. Problem is that the background is always transparent when I use CleanLooks style but when I switch to for example WindowsVista style everything works fine.
I'm using PyQt 10.4.3 on a Windows machine.
Here is a small code sample from which you can see this strange behavior.
from PyQt4 import QtGui,QtCore
from PyQt4.QtCore import Qt
class Selector(QtGui.QRubberBand):
"""
Custom QRubberBand
"""
def __init__(self,*arg,**kwargs):
super(Selector,self).__init__(*arg,**kwargs)
def paintEvent(self, QPaintEvent):
painter = QtGui.QPainter(self)
# set pen
painter.setPen(QtGui.QPen(Qt.blue,4))
# set brush
color = QtGui.QColor(Qt.blue)
painter.setBrush(QtGui.QBrush(color))
# set opacity
painter.setOpacity(0.3)
# draw rectangle
painter.drawRect(QPaintEvent.rect())
class Panel(QtGui.QWidget):
def __init__(self,parent = None):
super(Panel,self).__init__(parent)
self.rubberBand = Selector(QtGui.QRubberBand.Rectangle,self)
def mousePressEvent(self, QMouseEvent):
self.clickPosition = QMouseEvent.pos()
self.rubberBand.setGeometry(QtCore.QRect(self.clickPosition,QtCore.QSize()))
self.rubberBand.show()
def mouseMoveEvent(self, QMouseEvent):
pos = QMouseEvent.pos()
self.rubberBand.setGeometry(QtCore.QRect(self.clickPosition,pos).normalized())
def mouseReleaseEvent(self, QMouseEvent):
self.rubberBand.hide()
if __name__ == "__main__":
import sys
app = QtGui.QApplication([])
QtGui.QApplication.setStyle("cleanlooks")
pn = Panel()
pn.show()
sys.exit(app.exec_())