I use PyQt5 and python 3.6
I use the QtWidgets.QGraphicsView only to determine mouse position data and I want to paint in the background.
How can I set the QtWidgets.QGraphicsView transparent?
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Controller(QtWidgets.QMainWindow):
def __init__(self, setting):
super().__init__()
self.setGeometry(50, 150, 1610, 1207)
self.graphicsView = QtWidgets.QGraphicsView()
self.graphicsView.setMouseTracking(True)
self.graphicsView.viewport().installEventFilter(self)
self.graphicsView.setObjectName("graphicsView")
self.setCentralWidget(self.graphicsView)
def paintEvent(self, event):
painter = QtGui.QPainter(self)
#paint something
def eventFilter(self, source, event):
if event.type() == QtCore.QEvent.MouseMove:
if event.buttons() == QtCore.Qt.NoButton:
pos = event.pos()
print(str(pos.x())+' '+ str(pos.y()))
else:
pass # do other stuff
return QtGui.QWindow.eventFilter(self, source, event)
this is only a example class.
thank you in advance.
I have tried that out!
self.graphicsView.setStyleSheet("background:transparent;")
this works for me
In my case, I had to specify the backgroud color and not the background. So:
self.graphicsView.setStyleSheet("background-color: transparent;")
I use Qt 5.14.1 on C++
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.