4

Is it possible to remove the divider line between two widgets that were added to the status bar using .addPermanentWidget()? I suspect that it is possible, but I haven't really found any literature on how to proceed.

import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QStatusBar, QLabel


class MainWindow(QMainWindow):

    def __init__(self):
        QMainWindow.__init__(self)

        statusBar = QStatusBar()
        self.setStatusBar(statusBar)
        statusBar.addPermanentWidget(QLabel("Label: "))
        statusBar.addPermanentWidget(QLabel("Data"))


app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())

enter image description here

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
artomason
  • 3,625
  • 5
  • 20
  • 43
  • Not all widget styles will draw separators. What platform are you on, and what is the output of `QApplication.style().objectName()`? – ekhumoro Mar 09 '18 at 17:57
  • Output is windowsvista, I'm currently developing under Windows 10. – artomason Mar 09 '18 at 18:04
  • Does it make any difference if you use the default status-bar, rather than setting a new one? It probably won't, but it would be good to rule that out. – ekhumoro Mar 09 '18 at 18:11
  • @ekhumoro there was not change using the default status-bar. – artomason Mar 09 '18 at 18:18
  • 1
    The [stylesheet examples](https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qstatusbar) suggest it might be possible to set the border to zero for status-bar items. But I can't test it myself, so I have no idea whether that will work. If it doesn't, it will probably be necessary to reimplement the paint-event of `QStatusBar`. – ekhumoro Mar 09 '18 at 18:22
  • @ekhumoro Thank you for pointing me in the right direction. Setting the `QStatusBar::Item` stylesheet removed the divider.. – artomason Mar 09 '18 at 18:28

2 Answers2

6

In order to remove the divider between the two elements you need to set the stylesheet for QStatusBar::item in either Qt Creator, or the project source.

Qt Creator Example:

enter image description here

Project Source Example:

import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QStatusBar, QLabel


class MainWindow(QMainWindow):

    def __init__(self):
        QMainWindow.__init__(self)

        statusBar = QStatusBar()

        statusBar.setStyleSheet('QStatusBar::item {border: None;}')

        self.setStatusBar(statusBar)
        statusBar.addPermanentWidget(QLabel("Label: "))
        statusBar.addPermanentWidget(QLabel("Data"))


app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
artomason
  • 3,625
  • 5
  • 20
  • 43
1

Another way is to combine several widgets into one to group them, something like the C++ below:

    QWidget *widget = new QWidget;
    QLayout* layout = new QHBoxLayout(widget);
    layout->setMargin(0);

    QLabel *label = new QLabel;
    label->setText("Recording status");
    layout->addWidget(label);

    QLabel *m_RecordingStatus = new QLabel;
    m_RecordingStatus->setFrameShape(QFrame::Shape::Box);
    m_RecordingStatus->setFixedWidth(100);

    layout->addWidget(m_RecordingStatus);
    ui.m_statusBar->addPermanentWidget(widget);

You can group associated widgets to be together between dividers.

imoir
  • 11
  • 2