QStatusBar showMessage() not hiding normal status bar contents
Hello all,
I have a simple application where I am trying to use a QMainWindow with a QStatusBar. There are QLabels set and they update perfectly. Now I added a status->showMessage("test", 5000); which should display the message "test" for 5 seconds over the whole status bar, i.e. hiding currently set text in the QLabels. For some reason my machine shows the message for 5 seconds but I can see the QLabel information at the same time.
Firstly has anyone experienced this before? and Second, is there a way to force a White background of the showMessage() instead of invisible? After reading the docs some more, it is acting line I have used the addPermanentWidget() instead of addWidget(), where the temporary message will not hide the existing data on the status bar.
Here is a sample code program that compiles and shows the issue, I will also try to compile on another machine to see if it is machine based. When the program is compiled and run, I see the status bar leftmost position says "position 0 status" and on top of that I can kind of read the showMessage() of "test" for the 10 seconds, then it disappears and looks normal. Any thoughts?
testStatusBar.pro:
Code:
HEADERS += mytest.h
SOURCES += mytest.cpp \
main.cpp
main.cpp
Code:
#include <QtGui/QApplication>
#include "mytest.h"
int main(int argc, char * argv[])
{
mytest w;
w.show();
return a.exec();
}
mytest.cpp
Code:
#include "mytest.h"
{
le1->setText("Just a temp line edit for now...");
//set up status bar
stat0
= new QLabel("position 0 status");
status->addWidget(stat0,1);
status->addWidget(stat1,0);
status->addWidget(stat2,0);
setCentralWidget(le1);
setStatusBar(status);
setMinimumSize(600,480);
status->showMessage("test",10000);
}
mytest.h
Code:
#ifndef MYTEST_H
#define MYTEST_H
#include <QMainWindow>
#include <QtGui>
#include <QDebug>
{
Q_OBJECT
public:
private:
QLabel *stat0,
*stat1,
*stat2;
};
#endif // MYTEST_H
Thanks,
AlphaWolfXV
PS: Using QTCreator 1.2.1 (QT 4.5.2) / Windows Vista
- Just tried on QTCreator 1.3.0 (QT 4.6.0) / Windows Vista
Re: QStatusBar showMessage() not hiding normal status bar contents
For the time being...
I was calling the showmessage() on creation of the main window. If it is moved to later, like on a button click or a signal, it works fine. If anyone has any ideas on why this is the case please advise, but for now it is working as expected as long as I wait for the mytest::mytest() to be created.
Thanks,
AlphaWolfXV
Re: QStatusBar showMessage() not hiding normal status bar contents
In a QMainWindow you don't need to explicitly create your custom status bar. Just use QMainWindow::statusBar() and let QMainWindow create it for you:
http://qt.nokia.com/doc/4.6/qmainwindow.html#statusBar
Maybe your status bar is somehow conflicting with the one created by QMainWindow.