无法完全删除PyQt QGraphicsView的边框 [英] Unable to fully remove border of PyQt QGraphicsView
问题描述
我尝试在QGraphicsView上调用 self.setStyleSheet("background:transparent; border:transparent;")
,但它在顶部边缘仍留有1像素的边界.我也尝试过用 border-style:none;
替换 border:transparent;
,但是它也不起作用.
I have tried calling self.setStyleSheet("background: transparent; border: transparent;")
on a QGraphicsView, but it still leaves a 1 pixel border on the top edge. I have also tried replacing border: transparent;
with border-style: none;
, but it didn't work either.
以下是问题的屏幕截图:
Here is a screenshot of the problem:
什么命令将从QGraphicsView中完全删除边框?
What command will fully remove the border from the QGraphicsView?
推荐答案
您可以使用以下CSS规则之一:
You can use one of the following css rule:
graphicsView.setStyleSheet("border-width: 0px; border-style: solid")
或
graphicsView.setStyleSheet("border: 0px")
您的边框应该消失了.
import sys
from PyQt4.QtGui import *
class Ui(QWidget):
def __init__(self, parent=None):
QWidget.__init__(self, parent)
graphicsView = QGraphicsView()
graphicsView.setStyleSheet("border: 0px")
grid = QGridLayout()
grid.addWidget(graphicsView)
self.setLayout(grid)
app = QApplication(sys.argv)
ui = Ui()
ui.show()
sys.exit(app.exec_())
以下是具有默认样式的小部件:
Here is the widget with the default style:
现在已应用样式的小部件:
And now the widget with the style applied:
这篇关于无法完全删除PyQt QGraphicsView的边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!