无法完全去除的PyQt的QGraphicsView

问题描述:

我已经打过电话self.setStyleSheet("background: transparent; border: transparent;")上的QGraphicsView的边界,但仍留下了1个像素的边框上的顶边。我也试图与border-style: none;更换border: transparent;,但它也不能工作。无法完全去除的PyQt的QGraphicsView

这是问题的一个截图:

Problematic line

什么命令将完全从的QGraphicsView删除边框?

您可以使用下面的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_()) 

这里是默认样式的小工具:

http://i.stack.imgur.com/gpwaW.png

而现在应用的风格的小部件:

http://i.stack.imgur.com/A8K4u.png

+0

你举的例子有同样的问题。我用截图更新了这个问题。 –

+1

我提供的例子是在Mac OS X和Windows上工作,你使用的是什么版本的Qt/PyQt?我在PyQt Qt 4.7.3和4.8.3上。从我在屏幕截图上看到的,你已经有了一个占据你窗口的风格,你确定它不覆盖你的样式表吗? –

+0

我在Kubuntu 11.04上使用Qt 4.7.2。花哨的窗口颜色只是我的系统主题;甚至在使用默认主题时也会出现问题。 –

如果QGraphicsView是*窗口,尝试:

self.setContentsMargins(QMargins()) 

如果没有,你叫QGraphicsView和顶层窗口之间的每一个布局和窗口小部件相同的功能(该功能在这两个类中定义)。

PS:QMargins()是QtCore的一部分,当它的构造函数被调用不带任何参数,四个边距设置为0。

+0

有用的提示,但它不是删除线。 –