How to customise QGroupBox title in PyQt5?
<p>Here's a piece of code that creates a simple QGroupBox:</p>

<pre><code>from PyQt5.QtWidgets import (QApplication, QWidget,
                             QGroupBox, QGridLayout)

class QGroupBoxTest(QWidget):
  def __init__(self):
    super().__init__()
    self.initUI()

  def initUI(self):
    gb = QGroupBox()
    gb.setTitle('QGroupBox title')

    appLayout = QGridLayout()
    appLayout.addWidget(gb, 0, 0)
    self.setLayout(appLayout)

    self.setWindowTitle('QGroupBox test window')
    self.setGeometry(300, 300, 300, 200)

if __name__ == "__main__":

  import sys

  app = QApplication(sys.argv)
  test = QGroupBoxTest()
  test.show()

  sys.exit(app.exec_())
</code></pre>

<p>and here's what the output looks like to me:</p>

<p><a href="https://postimg.org/image/6kga2ljjd/" rel="nofollow"><img src="https://s12.postimg.org/q2axijgh9/qgb_1.jpg" alt="qgb-1.jpg"></a></p>

<p>Now let's say I want to add some style to it and I do this by adding this line to the initUI method:</p>

<pre><code>gb.setStyleSheet("border: 1px solid gray; border-radius: 5px")
</code></pre>

<p>here's the output:</p>

<p><a href="https://postimg.org/image/ign5gvbzv/" rel="nofollow"><img src="https://s9.postimg.org/lnhp0hwfz/qgb_1.jpg" alt="qgb-1.jpg"></a></p>

<p>As can be clearly seen from the pic, the title has ended up inside the frame and now is overlapping the frame border.</p>

<p>So I have three questions actually:</p>

<ol>
<li>Why did the title move?</li>
<li>How do I move it about and place it wherever I want (if possible)?</li>
<li>What if I simply want to round off border corners without specifying the border-style property. Let's say I want the border-style to stay the same as in the first pic but with rounded corners. How do I do that?</li>
</ol>

<p><strong>1)</strong> Probably that's the default QT placement, in the first image the  platform style is used, and its take care of borders and title placement, when you change the stylesheet you override something and you get the ugly placement.</p>

<p><strong>2)</strong> You can control the "title" position using the <code>QGroupBox:title</code>  controls, for example:</p>

<pre><code>gb.setStyleSheet('QGroupBox:title {'
                 'subcontrol-origin: margin;'
                 'subcontrol-position: top center;'
                 'padding-left: 10px;'
                 'padding-right: 10px; }')
</code></pre>

<p>will result in something like this:</p>

<p><a href="https://i.stack.imgur.com/vAdF4.png" rel="nofollow"><img src="https://i.stack.imgur.com/vAdF4.png" alt="title"></a></p>

<p><del><strong>3)</strong> My suggestion is to create different strings for the stylesheet attributes you want to change, then compose them to create the style you want.</del></p>

python css pyqt5