Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove the divider between widgets when using `statusBar.addPermanentWidget()`?

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

like image 347
artomason Avatar asked Oct 17 '25 11:10

artomason


2 Answers

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_())
like image 96
artomason Avatar answered Oct 19 '25 01:10

artomason


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.

like image 30
imoir Avatar answered Oct 18 '25 23:10

imoir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!