无法完全移除PyQt QGraphicsView的边框

7
我尝试在QGraphicsView上调用self.setStyleSheet("background: transparent; border: transparent;"),但仍然会在顶部边缘留下1像素的边框。我还尝试将border: transparent;替换为border-style: none;,但也没有起作用。
这是问题的截图: Problematic line 有什么命令可以完全删除QGraphicsView的边框?
2个回答

10

您可以使用以下任一CSS规则:

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_())

这是默认样式的小部件:

输入图像描述

现在应用了样式的小部件:

输入图像描述


你的例子有同样的问题。我已经在问题中更新了一张截图。 - D K
1
我提供的示例在Mac Os X和Windows上运行,你使用的是哪个版本的Qt / PyQt?我使用的是PyQt Qt 4.7.3和4.8.3。从你的截图中看到,你已经有一个样式接管了你的窗口,你确定它没有覆盖你的样式表吗? - Kel Solaar
我正在Kubuntu 11.04上使用Qt 4.7.2。花哨的窗口颜色只是我的系统主题;即使使用默认主题,问题仍会发生。 - D K
graphicsView是否显示任何边框样式覆盖?例如:graphicsView.setStyleSheet("border: 8px solid red;") - Kel Solaar
还有其他关于问题的想法吗?(“完美运行”是指8像素粗的红线)。 - D K
显示剩余2条评论

0

如果QGraphicsView是顶层窗口,请尝试:

self.setContentsMargins(QMargins())

如果不是这样,您需要在QGraphicsView和顶层窗口之间的所有布局和小部件上调用相同的函数(该函数在两个类中都定义)。
PS:QMargins()是QtCore的一部分,当它的构造函数没有任何参数时,四个边距都设置为0。

有用的提示,但它并没有删除该行。 - D K

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接