Results 1 to 3 of 3

Thread: Newbie dealing with statusbar incluiding widgets.

  1. #1
    Join Date
    Jan 2010
    Posts
    3
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question Newbie dealing with statusbar incluiding widgets.

    Hi,
    Im newbie in QT and C++...
    Im trying to add widgets (label and progressbar) to statusbar and found 2 ways (I think...):

    1- create the widgets and add them to statusbar in main class. this works OK!! but I dont know how to update the progressbar within mainwindow class... I stopped here...

    2- I see in this forum: create the widgets and add them to statusbar in mainwindow class (maybe is more simple to access to update values) but i doesnt work... I stopped here....

    Anyone please assist me?

    I post the code of my second option (may be the best???):

    Mainwindow.h :
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include <QUrl>
    6. #include <QMap>
    7. #include <QProgressBar>
    8. #include <QHBoxLayout>
    9. #include <QLabel>
    10.  
    11.  
    12. namespace Ui {
    13. class MainWindow;
    14. }
    15.  
    16. class MainWindow : public QMainWindow
    17. {
    18. Q_OBJECT
    19.  
    20. public:
    21. explicit MainWindow(QWidget *parent = 0);
    22. ~MainWindow();
    23.  
    24. private:
    25. void init();
    26. void createStatusBar();
    27.  
    28. Ui::MainWindow *ui;
    29. QMap<QString, int> Globales;
    30. // QFrame status_frame;
    31. // QHBoxLayout layout;
    32. QLabel *box;
    33.  
    34. private slots:
    35. void on_Web_loadProgress(int progress);
    36. void on_Web_urlChanged(QUrl);
    37. void on_Web_loadStarted();
    38. void on_BtnLogin_toggled(bool checked);
    39. };
    40.  
    41. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cpp :
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include <QWebSettings>
    4. #include <QProgressBar>
    5. #include <QLabel>
    6. #include <QStatusBar>
    7. #include <QProgressBar>
    8.  
    9.  
    10. MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow)
    11. {
    12. // Rutinas de Inicio
    13. createStatusBar();
    14. init();
    15.  
    16. ui->setupUi(this);
    17.  
    18. }
    19.  
    20. MainWindow::~MainWindow()
    21. {
    22. delete ui;
    23. }
    24.  
    25. void MainWindow::on_BtnLogin_toggled(bool checked)
    26. {
    27. if (checked) {
    28. //login
    29. Globales["Estado"] = 0;
    30. ui->Web->load(QUrl(ui->txtURL->text()));
    31. }
    32. else{
    33. //logout.
    34. ui->Web->load(QUrl("http://..."));
    35. Globales["Estado"] = 0;
    36. }
    37. }
    38.  
    39. void MainWindow::on_Web_loadStarted()
    40. {
    41. // here I intent to show the progressbar
    42. //ui->statusBar->pBar->show();
    43. }
    44.  
    45. void MainWindow::on_Web_urlChanged(QUrl newurl)
    46. {
    47. ui->LogNav->setTextColor(QColor("blue"));
    48. ui->LogNav->append(newurl.toString());
    49. }
    50.  
    51. void MainWindow::init()
    52. {
    53. //Fijar seteos del browser
    54. QWebSettings::globalSettings()->setAttribute(QWebSettings::AutoLoadImages, false);
    55.  
    56. }
    57.  
    58. void MainWindow::on_Web_loadProgress(int progress)
    59. {
    60. // Here I intent to update the progressbar
    61. }
    62.  
    63. void MainWindow::createStatusBar()
    64. {
    65. // status_frame = new QFrame();
    66. // status_frame->setFrameStyle(QFrame::Panel | QFrame::Sunken);
    67.  
    68. // layout = new QHBoxLayout(status_frame);
    69. // layout->setContentsMargins(0, 0, 0, 0);
    70.  
    71. bar = new QProgressBar();
    72. bar->setMaximumHeight(10);
    73. bar->setMaximumWidth(100);
    74. bar->setValue(80); //for testing
    75.  
    76. box = new QLabel("Check Mode");
    77.  
    78. // Two Options: Which is right ???
    79. //ui->statusBar->addWidget(bar);
    80. //ui->statusBar->addWidget(box);
    81. statusBar()->addWidget(bar);
    82. statusBar()->addWidget(box);
    83. }
    To copy to clipboard, switch view to plain text mode 

    Best regards!!!

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    507
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Newbie dealing with statusbar incluiding widgets.

    Hi, maybe it already helps to move setupUi() to be the first command in constructor of MainWindow.

    Ginsengelf

    PS: statusBar()-method should be Ok in createStatusBar(), in your pasted code the other method should not work or even crash because ui is not set up when you call createStatusBar()

  3. The following user says thank you to Ginsengelf for this useful post:

    chavetaz (6th July 2010)

  4. #3
    Join Date
    Jan 2010
    Posts
    3
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Newbie dealing with statusbar incluiding widgets.

    Hi Amigo!
    it's works perfectly!!!

    SetupUi() create the statusbar....


    Many Thanks ! ! !

Similar Threads

  1. access to widgets of statusbar
    By navid in forum Newbie
    Replies: 1
    Last Post: 5th December 2009, 12:27
  2. Interview: Show statusbar or other widgets in a view?
    By uiop21 in forum Qt Programming
    Replies: 6
    Last Post: 6th March 2008, 16:51
  3. Replies: 2
    Last Post: 15th February 2008, 01:21
  4. Replies: 2
    Last Post: 7th January 2007, 21:07
  5. dealing individual objects
    By kingslee in forum General Programming
    Replies: 9
    Last Post: 15th November 2006, 01:28

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.