Results 1 to 3 of 3

Thread: QStatusBar showMessage() not hiding normal status bar contents

  1. #1
    Join Date
    Aug 2008
    Posts
    38
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default 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:

    Qt Code:
    1. HEADERS += mytest.h
    2. SOURCES += mytest.cpp \
    3. main.cpp
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "mytest.h"
    3. int main(int argc, char * argv[])
    4. {
    5. QApplication a(argc, argv);
    6. mytest w;
    7. w.show();
    8. return a.exec();
    9. }
    To copy to clipboard, switch view to plain text mode 

    mytest.cpp
    Qt Code:
    1. #include "mytest.h"
    2.  
    3. mytest::mytest(QWidget *parent)
    4. :QMainWindow(parent)
    5. {
    6. le1 = new QLineEdit(this);
    7. le1->setText("Just a temp line edit for now...");
    8. //set up status bar
    9. stat0 = new QLabel("position 0 status");
    10. stat1 = new QLabel(" (1) ");
    11. stat2 = new QLabel(" (2) ");
    12. status = new QStatusBar(this);
    13. status->addWidget(stat0,1);
    14. status->addWidget(stat1,0);
    15. status->addWidget(stat2,0);
    16. setCentralWidget(le1);
    17. setStatusBar(status);
    18. setMinimumSize(600,480);
    19. status->showMessage("test",10000);
    20. }
    To copy to clipboard, switch view to plain text mode 

    mytest.h
    Qt Code:
    1. #ifndef MYTEST_H
    2. #define MYTEST_H
    3.  
    4. #include <QMainWindow>
    5. #include <QtGui>
    6. #include <QDebug>
    7. class mytest : public QMainWindow
    8. {
    9. Q_OBJECT
    10. public:
    11. mytest(QWidget *parent = 0);
    12. private:
    13. QLabel *stat0, *stat1, *stat2;
    14. QLineEdit *le1;
    15. QStatusBar *status;
    16. };
    17.  
    18. #endif // MYTEST_H
    To copy to clipboard, switch view to plain text mode 

    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
    Last edited by AlphaWolfXV; 28th January 2010 at 12:13.

  2. #2
    Join Date
    Aug 2008
    Posts
    38
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default 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

  3. #3
    Join Date
    Apr 2009
    Location
    Italy
    Posts
    70
    Thanks
    23
    Thanked 15 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.

Similar Threads

  1. QStatusBar
    By newermind in forum Qt Programming
    Replies: 3
    Last Post: 1st June 2009, 21:48
  2. QSystemTrayIcon::showMessage
    By radojkod in forum Qt Programming
    Replies: 0
    Last Post: 4th December 2008, 13:13
  3. QStatusBar: XP-Style?
    By bpetty in forum Newbie
    Replies: 1
    Last Post: 3rd September 2007, 20:06
  4. Showing QMainWindow without showing a child QWidget
    By discostu in forum Qt Programming
    Replies: 3
    Last Post: 4th March 2007, 09:03
  5. about QStatusBar
    By Pang in forum Qt Programming
    Replies: 1
    Last Post: 16th November 2006, 04:15

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.