Unable to fully remove border of PyQt QGraphicsView
Asked Answered
G

2

7

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:

Problematic line

What command will fully remove the border from the QGraphicsView?

Greenebaum answered 6/9, 2011 at 20:42 Comment(0)
C
10

You can use one of the following css rule:

graphicsView.setStyleSheet("border-width: 0px; border-style: solid")

or

graphicsView.setStyleSheet("border: 0px")

Your border should disappear.

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:

enter image description here

And now the widget with the style applied:

enter image description here

Cavalcade answered 6/9, 2011 at 22:9 Comment(7)
Your example has the same problem. I've updated the question with a screenshot.Greenebaum
The example I provided is working on Mac Os X and Windows, what version of Qt / PyQt are you using? I'm on PyQt Qt 4.7.3 and 4.8.3. From what I see on your screenshot, you already have a style taking over your window, are you sure it is not overriding your stylesheet?Cavalcade
I am using Qt 4.7.2 on Kubuntu 11.04. The fancy window color is just my system theme; the problem occurs even when using the default theme.Greenebaum
Does the graphicsView display any border style override at all? for instance something like that: graphicsView.setStyleSheet("border: 8px solid red;")Cavalcade
Any other ideas of what the problem might be? (The "works perfectly" was referring to the 8 pixel thick red line).Greenebaum
I edited my reply and added 2 images from Linux, seems to works here also. It's maybe worth a check on Qt Bugs Tracker: bugreports.qt.nokia.comCavalcade
Okay. I've reported a bug, and we'll see what happens. I'll mark your answer as correct.Greenebaum
A
0

If the QGraphicsView is the top level window, try:

self.setContentsMargins(QMargins())

If not, you call the same function on every layouts and widgets (the function is defined in both classes) between the QGraphicsView and the top level window.

PS: QMargins() is part of QtCore, and when its constructor is called without any parameters, the four margins are set to 0.

Anaerobe answered 6/9, 2011 at 23:31 Comment(1)
Useful tip, but it isn't removing the line.Greenebaum

© 2022 - 2024 — McMap. All rights reserved.