Styling a QFrame's border to match a QTextEdit

  • I have a window with several QDockWidgets (using PyQt5). One of the dock widgets contains a read-only QTextEdit (with no additional styling). Another dock widget contains a QFrame (with some content inside of it). I'm trying to style the QFrame to look the same as the QTextEdit. I have everything identical, except for the border...

    Here's a picture of the two:

    It looks like the border on the QFrame is thicker than the border on the QTextEdit, but setLineWidth doesn't change anything (I'm guessing because it's a StyledPanel).

    Here's the Python code I have to set up the QFrame (it contains a QVBoxLayout with two widgets, one currently empty, one contains a QGridWidget, but nothing has been added to it in the picture):

    self.widget = QFrame(self)
    layout = QVBoxLayout(self.widget)
    layout.setContentsMargins(0, 0, 0, 0)
    self.widget.setContentsMargins(12, 12, 12, 12)
    header_widget = QWidget(self)
    grid_widget = QWidget(self)
    header_widget.setContentsMargins(0, 0, 0, 0)
    grid_widget.setContentsMargins(0, 0, 0, 0)
    self._pal = QPalette()
    self._pal.setColor(QPalette.Window, QColor(255, 255, 255, 255))
    layout.addWidget(header_widget, 0)
    layout.addWidget(grid_widget, 1)
    self._layout = QGridLayout(grid_widget)
    self._layout.setContentsMargins(5, 5, 5, 5)

    I've tried setting the border style to Box and Panel, but both of those styles look fairly different. I am able to set a thicker border using setLineWidth, but even at 1 the border still looks too thick. I tried setting a stylesheet for the QFrame, but ended up with padding between the border and my content that I couldn't remove (set padding: 0; margin: 0; but it still remained).

    I'd appreciate any suggestions! Thanks!

  • Qt Champions 2017

    what platform are you on ?
    In win 10, the look 100% the same when set to same settings
    TExtEdit uses a QFrame for the frame.

    alt text

    alt text

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.