【问题标题】:PyQt5 QGraphicsView transparent backgroundPyQt5 QGraphicsView 透明背景
【发布时间】:2020-02-27 04:34:37
【问题描述】:

我使用 PyQt5 和 python 3.6

我只使用 QtWidgets.QGraphicsView 来确定鼠标位置数据,我想在后台绘制。

如何设置 QtWidgets.QGraphicsView 透明?

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)

这只是一个示例类。

提前谢谢你。

【问题讨论】:

  • 使用 setStyleSheet("background: transparent") 或 PyQt 的任何等效项?
  • 我检查了它,它就在那里。有用。谢谢!

标签: python python-3.x pyqt5


【解决方案1】:

我已经试过了!

self.graphicsView.setStyleSheet("background:transparent;")

这对我有用

【讨论】:

    【解决方案2】:

    就我而言,我必须指定背景颜色而不是背景。 所以:

    self.graphicsView.setStyleSheet("background-color: transparent;")
    

    我在 C++ 上使用 Qt 5.14.1

    【讨论】:

      猜你喜欢
      • 2018-04-23
      • 1970-01-01
      • 2017-12-03
      • 2011-03-08
      • 2021-09-20
      • 2019-02-07
      • 2020-10-15
      • 2017-06-22
      • 2010-10-20
      相关资源
      最近更新 更多