PDA

View Full Version : How to divide a status bar in parts



franco.amato
24th January 2011, 22:58
Hi to all,
I would create a status bar in my application and I would have 3 parts on it to add different messanges per part.
I also would add a little image in one of them.
How can I do it?
Best Regards,
Franco

Lykurg
24th January 2011, 23:01
Have you tried QStatusBar::addPermanentWidget() or QStatusBar::insertWidget()?

franco.amato
24th January 2011, 23:18
Have you tried QStatusBar::addPermanentWidget() or QStatusBar::insertWidget()?

Dear Lykurg,
is not exactly what I need. What I need is divide my status bar in 3 parts as you can see in this image:
http://www.lgiris.com/ps/products/idata/idataeac.htm
look at ths status bar of the software in the link. I would reproduce the same behavior.
Regards

Lykurg
24th January 2011, 23:42
Oh please, could you try at least read the small portions of documentation I pointed you? It is exactly what you need! Add three widgets and you have split your status bar up. With the stretch you can control the width of the widgets. Or if you like you can only add one widget for the whole space. Then this widget must divide itself into three parts etc.

franco.amato
24th January 2011, 23:53
Oh please, could you try at least read the small portions of documentation I pointed you? It is exactly what you need! Add three widgets and you have split your status bar up. With the stretch you can control the width of the widgets. Or if you like you can only add one widget for the whole space. Then this widget must divide itself into three parts etc.

Ah sorry I didn't get you before. For example with wxWidget you can explicitly split a status bar without adding widgets and refer to them as index 0 to n-1.
Thanx

ChrisW67
25th January 2011, 00:07
Did you actually try QStatusBar::addPermanentWidget() or QStatusBar::insertWidget() a couple of times before proclaiming that it did not give you the solution to your problem?


#include <QtGui>
#include <QDebug>

class MainWindow: public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *p = 0): QMainWindow(p) {
QWidget *central = new QWidget(this);
setCentralWidget(central);

// Do multipart status bar
m_statusLeft = new QLabel("Left", this);
m_statusLeft->setFrameStyle(QFrame::Panel | QFrame::Sunken);
m_statusMiddle = new QLabel("Middle", this);
m_statusMiddle->setFrameStyle(QFrame::Panel | QFrame::Sunken);
m_statusRight = new QLabel("Right", this);
m_statusRight->setFrameStyle(QFrame::Panel | QFrame::Sunken);
statusBar()->addPermanentWidget(m_statusLeft, 1);
statusBar()->addPermanentWidget(m_statusMiddle, 1);
statusBar()->addPermanentWidget(m_statusRight, 2);
}
public slots:
private:
QLabel * m_statusLeft;
QLabel * m_statusMiddle;
QLabel * m_statusRight;
};

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

MainWindow m;
m.show();
return app.exec();
}
#include "main.moc"

franco.amato
25th January 2011, 00:11
Cris I told to Lykurg that I didn't understand well before the last post so please read my post before to reply thank you.
Regards

ChrisW67
25th January 2011, 00:18
Both Lykurg's reply and your reply were posted while I was writing mine (amongst answering phones for work). Unfortunately there is no delete post so that I could remove the now unneeded response.

franco.amato
25th January 2011, 00:21
Both Lykurg's reply and your reply were posted while I was writing mine (amongst answering phones for work). Unfortunately there is no delete post so that I could remove the now unneeded response.

Hi Chris I know, doesn't matter. For that I proposed to wysota to add such feature but he doens't want.
Meanwhile thank you very much for the example, it's very usefull.
Regards

Lykurg
25th January 2011, 08:06
For that I proposed to wysota to add such feature but he doens't want.
We don't need such a feature. Based on the time stamp one can imagine that it was posted at the "same" time and everybody has the posibillity to edit his post and add something like "EDIT: too late...". Then all is clear. And besides: It is good that ChrisW67 hasn't delete his message, because of the code example!

franco.amato
26th January 2011, 02:16
Hi,
how is possible to change the text of one of the parts when the application is running?
And how is possible to add a small icon again when running?
Regards

wysota
26th January 2011, 02:40
We don't need such a feature. Based on the time stamp one can imagine that it was posted at the "same" time and everybody has the posibillity to edit his post and add something like "EDIT: too late...". Then all is clear.
The "Preview Post" button can do miracles in this situation ;)


Hi,
how is possible to change the text of one of the parts when the application is running?
And how is possible to add a small icon again when running?

The "parts" are usually labels. You know how to change text of a label or add an icon to it, right?

franco.amato
26th January 2011, 02:41
Yes Wysota I solved. Thank you very much.
Best