PDA

View Full Version : QDialog StatusBar



skuda
3rd December 2007, 11:26
hello i would like to add a status bar to a normal dialog to do any information relative to active widget in the dialog (i prefer this to a tooltip) but i cant find how to do this in qt documentation, it seems the status bar it is only used in qmainwindow, how can i add a statusbar to a normal dialog? Thanks.

wysota
3rd December 2007, 12:06
Yes, you can add a status bar, but you have to do it manually using a layout.

#include <QDialog>
#include <QStatusBar>
#include <QLayout>
#include <QApplication>
#include <QTextEdit>

int main(int argc, char **argv){
QApplication app(argc, argv);
QDialog dlg;
QLayout *l = new QVBoxLayout(&dlg);
l->addWidget(new QTextEdit);
QStatusBar *b = new QStatusBar;
l->addWidget(b);
b->showMessage("XXX");
l->setMargin(0);
l->setSpacing(0);
return dlg.exec();
}

skuda
3rd December 2007, 15:22
the problem with this aproach it is that widgets inside the dialog dont update the status i have added to the layout although it have a statusTip setted

wysota
3rd December 2007, 15:27
You probably need to reimplement event() for the dialog and handle QEvent::StatusTip for all its children there.


#include <QDialog>
#include <QStatusBar>
#include <QLayout>
#include <QApplication>
#include <QTextEdit>
#include <QStatusTipEvent>

class Dialog : public QDialog {
public:
Dialog() : QDialog(){
QLayout *l = new QVBoxLayout(this);
QTextEdit *te = new QTextEdit;
te->setStatusTip("XXX");
l->addWidget(te);
bar = new QStatusBar;
l->addWidget(bar);
l->setMargin(0);
l->setSpacing(0);
}
private:
QStatusBar *bar;
protected:
bool event(QEvent *e){
if(e->type()==QEvent::StatusTip){
QStatusTipEvent *ev = (QStatusTipEvent*)e;
bar->showMessage(ev->tip());
return true;
}
return QDialog::event(e);
}
};

int main(int argc, char **argv){
QApplication app(argc, argv);
Dialog dlg;
return dlg.exec();
}

skuda
4th December 2007, 11:04
this code works perfectly, many thanks wysota.

shawno
16th July 2010, 01:07
I tried this maneuvre on a local status bar I have on each of my "tab" widgets (widgets within a QTabWidget). This local status bar does not behave like the main window status bar. The local messages only appear if the mouse hovers over the "tab" widget and while the mouse is over the "tab" widget the messages do not update. I'm doing tabbed searching of the local file system such that each "tab" widget (containing a QTreeView) performs a distinct search. I need the filepaths to permanently, and possibly rapidly, display and update on the local status bar regardless of the mouse position as I traverse the filesystem. Any ideas?