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 :
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QUrl>
#include <QMap>
#include <QProgressBar>
#include <QHBoxLayout>
#include <QLabel>
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
private:
void init();
void createStatusBar();
Ui::MainWindow *ui;
QMap<QString, int> Globales;
// QFrame status_frame;
// QHBoxLayout layout;
private slots:
void on_Web_loadProgress(int progress);
void on_Web_urlChanged
(QUrl);
void on_Web_loadStarted();
void on_BtnLogin_toggled(bool checked);
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QUrl>
#include <QMap>
#include <QProgressBar>
#include <QHBoxLayout>
#include <QLabel>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
void init();
void createStatusBar();
Ui::MainWindow *ui;
QMap<QString, int> Globales;
// QFrame status_frame;
// QHBoxLayout layout;
QProgressBar *bar;
QLabel *box;
private slots:
void on_Web_loadProgress(int progress);
void on_Web_urlChanged(QUrl);
void on_Web_loadStarted();
void on_BtnLogin_toggled(bool checked);
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
mainwindow.cpp :
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QWebSettings>
#include <QProgressBar>
#include <QLabel>
#include <QStatusBar>
#include <QProgressBar>
{
// Rutinas de Inicio
createStatusBar();
init();
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_BtnLogin_toggled(bool checked)
{
if (checked) {
//login
Globales["Estado"] = 0;
ui
->Web
->load
(QUrl(ui
->txtURL
->text
()));
}
else{
//logout.
ui
->Web
->load
(QUrl("http://..."));
Globales["Estado"] = 0;
}
}
void MainWindow::on_Web_loadStarted()
{
// here I intent to show the progressbar
//ui->statusBar->pBar->show();
}
void MainWindow
::on_Web_urlChanged(QUrl newurl
) {
ui
->LogNav
->setTextColor
(QColor("blue"));
ui->LogNav->append(newurl.toString());
}
void MainWindow::init()
{
//Fijar seteos del browser
QWebSettings::globalSettings()->setAttribute(QWebSettings::AutoLoadImages, false);
}
void MainWindow::on_Web_loadProgress(int progress)
{
// Here I intent to update the progressbar
}
void MainWindow::createStatusBar()
{
// status_frame = new QFrame();
// status_frame->setFrameStyle(QFrame::Panel | QFrame::Sunken);
// layout = new QHBoxLayout(status_frame);
// layout->setContentsMargins(0, 0, 0, 0);
bar->setMaximumHeight(10);
bar->setMaximumWidth(100);
bar->setValue(80); //for testing
box
= new QLabel("Check Mode");
// Two Options: Which is right ???
//ui->statusBar->addWidget(bar);
//ui->statusBar->addWidget(box);
statusBar()->addWidget(bar);
statusBar()->addWidget(box);
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QWebSettings>
#include <QProgressBar>
#include <QLabel>
#include <QStatusBar>
#include <QProgressBar>
MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow)
{
// Rutinas de Inicio
createStatusBar();
init();
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_BtnLogin_toggled(bool checked)
{
if (checked) {
//login
Globales["Estado"] = 0;
ui->Web->load(QUrl(ui->txtURL->text()));
}
else{
//logout.
ui->Web->load(QUrl("http://..."));
Globales["Estado"] = 0;
}
}
void MainWindow::on_Web_loadStarted()
{
// here I intent to show the progressbar
//ui->statusBar->pBar->show();
}
void MainWindow::on_Web_urlChanged(QUrl newurl)
{
ui->LogNav->setTextColor(QColor("blue"));
ui->LogNav->append(newurl.toString());
}
void MainWindow::init()
{
//Fijar seteos del browser
QWebSettings::globalSettings()->setAttribute(QWebSettings::AutoLoadImages, false);
}
void MainWindow::on_Web_loadProgress(int progress)
{
// Here I intent to update the progressbar
}
void MainWindow::createStatusBar()
{
// status_frame = new QFrame();
// status_frame->setFrameStyle(QFrame::Panel | QFrame::Sunken);
// layout = new QHBoxLayout(status_frame);
// layout->setContentsMargins(0, 0, 0, 0);
bar = new QProgressBar();
bar->setMaximumHeight(10);
bar->setMaximumWidth(100);
bar->setValue(80); //for testing
box = new QLabel("Check Mode");
// Two Options: Which is right ???
//ui->statusBar->addWidget(bar);
//ui->statusBar->addWidget(box);
statusBar()->addWidget(bar);
statusBar()->addWidget(box);
}
To copy to clipboard, switch view to plain text mode
Best regards!!!
Bookmarks