Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Styling a QFrame's border to match a QTextEdit
Forum Updated to NodeBB v4.3 + New Features

Styling a QFrame's border to match a QTextEdit

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.5k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    GlowingApple
    wrote on last edited by
    #1

    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.setSpacing(0)
    layout.setContentsMargins(0, 0, 0, 0)
    self.widget.setLayout(layout)
    self.widget.setContentsMargins(12, 12, 12, 12)
    self.widget.setFrameStyle(QFrame.StyledPanel)
    self.setWidget(self.widget)
    header_widget = QWidget(self)
    grid_widget = QWidget(self)
    header_widget.setContentsMargins(0, 0, 0, 0)
    grid_widget.setContentsMargins(0, 0, 0, 0)
    header_widget.setAutoFillBackground(True)
    grid_widget.setAutoFillBackground(True)
    self._pal = QPalette()
    self._pal.setColor(QPalette.Window, QColor(255, 255, 255, 255))
    header_widget.setPalette(self._pal)
    grid_widget.setPalette(self._pal)
    layout.addWidget(header_widget, 0)
    layout.addWidget(grid_widget, 1)
    self._layout = QGridLayout(grid_widget)
    grid_widget.setLayout(self._layout)
    self._layout.setSpacing(5)
    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!
    Jayson

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      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

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved