Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to fully remove border of PyQt QGraphicsView

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?

like image 769
D K Avatar asked Sep 06 '11 20:09

D K


1 Answers

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

like image 66
Kel Solaar Avatar answered Nov 18 '22 03:11

Kel Solaar