PDA

View Full Version : How to do statusbar with separator or with frame.



Usernаme
22nd May 2010, 04:28
I want to do statusbar with any visual separator such as frame or horizontal line, but I don't know how to do this..
I try this:

QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addWidget(label1);
mainLayout->addWidget(label2);
bar = statusbar()->setLayout(mainLayout);

but this don't work

Usernаme
22nd May 2010, 04:33
Style Sheets?

Usernаme
22nd May 2010, 04:41
ok, now I know how to do this..
Is there any way to place several QLabel on statusBar()? I have done setLayout() but this don't work

Usernаme
22nd May 2010, 04:47
now I have one question - why setLayout don't work on qstatusbar?
I want to use setAligment() with QLabel, but it has no effect..

lbl->setAligment(Qt::AlignCentre);
bar->addWidget(lbl);

but lbl place in the left corner..

ChrisW67
22nd May 2010, 07:26
QStatusBar already has its own horizontal layout that you can just add widgets to:


#include <QtGui>
#include <QDebug>


int main(int argc, char **argv)
{
QApplication app(argc, argv);

QMainWindow win;

qDebug() << win.statusBar()->layout();

// Global
win.statusBar()->setStyleSheet(
"QStatusBar::item { border: 1px solid red; border-radius: 3px; } "
);

// or get more specific
// win.statusBar()->setStyleSheet(
// "QStatusBar::item { border: none; } "
// "QStatusBar QLabel { border: 1px solid blue; border-radius: 3px; }"
// );

QLabel *label1 = new QLabel("Text");
label1->setMinimumSize(label1->sizeHint());

QLabel *label2 = new QLabel("More text");
label2->setAlignment(Qt::AlignCenter);

win.statusBar()->addWidget(label1);
win.statusBar()->addWidget(label2, 1);

win.show();
return app.exec();
}


Your widget is given its minimum size unless you do something like set a stretch factor. Centre alignment means nothing if the box fits its content.