Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to equally distribute QLabels in QStatusBar
Hello, how can I equally distribute (for example three) QLabels in QStatusBar? I tried to add QHBoxLayout. But I cannot add Layout to QStatusBar, as it said it already has layout:
QWidget::setLayout: Attempting to set QLayout "" on QStatusBar "", which already has a layout
What about putting that layout on a "container" widget and then put that widget in the QStatusBar ?
@SGaist . Thanks, I already did similar as you suggested.
statusBar = new QStatusBar(); QLabel *statuslabel1 = new QLabel; QLabel *statuslabel2 = new QLabel; QLabel *statuslabel3 = new QLabel; statuslabel1->setText("Left"); statuslabel2->setText("Centre"); statuslabel3->setText("Right"); statusLayout = new QHBoxLayout; statusLayout->addWidget(statuslabel1); statusLayout->addStretch(); statusLayout->addWidget(statuslabel2); statusLayout->addStretch(); statusLayout->addWidget(statuslabel3); QWidget *container = new QWidget; container->setLayout(statusLayout); statusBar->addWidget(container);
This gave me like this statusBar.
This is not what I wanted, I wanted Left label to be at left, Centre to be at centre and Right label at right. Of course, they should retain their position even when the window is resized or at least when the application opens.
What I dont understand is why the statusBar is only 50% of available width.
@milan You should rather do
@jsulm . I get like this after the change. I removed widget stylesheets too in meantime.
You can see now, container widget is in right.