下面的代码生成一个黑色背景的窗口。不幸的是,背景是用细白线框起来的。
我尝试将其他背景参数设置为黑色,但没有奏效。
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QGraphicsView, QGraphicsScene
class GraphicsWindow(QGraphicsView):
def __init__(self, parent=None):
super(GraphicsWindow, self).__init__(parent)
scene = QGraphicsScene(self)
self.setScene(scene)
self.setBackgroundBrush(Qt.black)
def main():
app = QApplication(sys.argv)
graphics_window = GraphicsWindow()
graphics_window.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
我想创建一个全黑背景的窗口,但它的框架很细。
答案 0 :(得分:1)
您必须更改QGraphicsView的背景颜色,例如使用QPalette:
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPalette
from PyQt5.QtWidgets import QApplication, QGraphicsView, QGraphicsScene
class GraphicsWindow(QGraphicsView):
def __init__(self, parent=None):
super(GraphicsWindow, self).__init__(parent)
scene = QGraphicsScene(self)
self.setScene(scene)
self.setBackgroundBrush(Qt.black)
pal = self.palette()
pal.setColor(QPalette.Window, Qt.black)
self.setPalette(pal)
def main():
app = QApplication(sys.argv)
graphics_window = GraphicsWindow()
graphics_window.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
答案 1 :(得分:1)
您可以在类的init方法内添加CSS样式:
def __init__(self, parent=None):
super(GraphicsWindow, self).__init__(parent)
scene = QGraphicsScene(self)
self.setScene(scene)
self.setBackgroundBrush(Qt.black)
self.setStyleSheet("border:0px")