Results 1 to 6 of 6

Thread: QDialog StatusBar

  1. #1
    Join Date
    Oct 2007
    Posts
    65
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QDialog StatusBar

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDialog StatusBar

    Yes, you can add a status bar, but you have to do it manually using a layout.
    Qt Code:
    1. #include <QDialog>
    2. #include <QStatusBar>
    3. #include <QLayout>
    4. #include <QApplication>
    5. #include <QTextEdit>
    6.  
    7. int main(int argc, char **argv){
    8. QApplication app(argc, argv);
    9. QDialog dlg;
    10. QLayout *l = new QVBoxLayout(&dlg);
    11. l->addWidget(new QTextEdit);
    12. l->addWidget(b);
    13. b->showMessage("XXX");
    14. l->setMargin(0);
    15. l->setSpacing(0);
    16. return dlg.exec();
    17. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images

  3. The following 2 users say thank you to wysota for this useful post:

    nilot (7th April 2017), skuda (3rd December 2007)

  4. #3
    Join Date
    Oct 2007
    Posts
    65
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDialog StatusBar

    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

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDialog StatusBar

    You probably need to reimplement event() for the dialog and handle QEvent::StatusTip for all its children there.

    Qt Code:
    1. #include <QDialog>
    2. #include <QStatusBar>
    3. #include <QLayout>
    4. #include <QApplication>
    5. #include <QTextEdit>
    6. #include <QStatusTipEvent>
    7.  
    8. class Dialog : public QDialog {
    9. public:
    10. Dialog() : QDialog(){
    11. QLayout *l = new QVBoxLayout(this);
    12. QTextEdit *te = new QTextEdit;
    13. te->setStatusTip("XXX");
    14. l->addWidget(te);
    15. bar = new QStatusBar;
    16. l->addWidget(bar);
    17. l->setMargin(0);
    18. l->setSpacing(0);
    19. }
    20. private:
    21. QStatusBar *bar;
    22. protected:
    23. bool event(QEvent *e){
    24. if(e->type()==QEvent::StatusTip){
    25. bar->showMessage(ev->tip());
    26. return true;
    27. }
    28. return QDialog::event(e);
    29. }
    30. };
    31.  
    32. int main(int argc, char **argv){
    33. QApplication app(argc, argv);
    34. Dialog dlg;
    35. return dlg.exec();
    36. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 3rd December 2007 at 16:31. Reason: Added the example code

  6. The following user says thank you to wysota for this useful post:

    skuda (4th December 2007)

  7. #5
    Join Date
    Oct 2007
    Posts
    65
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDialog StatusBar

    this code works perfectly, many thanks wysota.

  8. #6
    Join Date
    Dec 2009
    Location
    Omaha, NE USA
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDialog StatusBar

    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?

Similar Threads

  1. QDialog margin and spacing
    By TheRonin in forum Qt Programming
    Replies: 4
    Last Post: 29th October 2007, 11:11
  2. statusBar() message color change
    By mclark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2007, 00:20
  3. QDialog / QListView problem
    By harakiri in forum Qt Programming
    Replies: 1
    Last Post: 10th July 2007, 19:31
  4. Resizing a QDialog to the content size
    By Nyphel in forum Qt Programming
    Replies: 8
    Last Post: 15th March 2007, 09:16
  5. Qdialog as a child widget
    By dave in forum Newbie
    Replies: 12
    Last Post: 14th November 2006, 10:43

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.