ITChristian
ITChristian

Reputation: 11271

Show status bar a default message

I have created a status bar in Qt. I am developing a webbrowser. When the user hovers a link the status bar shows the link hovered.

That works but how do I set a default text when the status bar is blank?

Is there any option to do this?

Upvotes: 1

Views: 6630

Answers (1)

Erik
Erik

Reputation: 2203

If you connect the linkHovered signal of the QWebPage to the statusBar, can't you simply check whether it is empty and then display whatever message you like?

The code below seems to do what you describe, but maybe I misunderstood what you were asking? Note: I simply created a QMainWindow which has a status bar by default.

#ifndef MYMAINWINDOW_H
#define MYMAINWINDOW_H

#include <QMainWindow>

#include "ui_mainwindow.h"

class MainWindow: public QMainWindow, private Ui::MainWindow
{
  Q_OBJECT

  public:
  MainWindow(QWidget *parent = 0) : QMainWindow(parent), defaultMessage("Default Message")  {
    setupUi(this);
    webView->load(QUrl("http://www.stackoverflow.com"));
    this->statusBar()->showMessage(defaultMessage);
    connect(webView->page(),SIGNAL(linkHovered(const QString & , const QString & , const QString & )),
            this, SLOT( hovered(const QString & , const QString & , const QString & ) ) );
  }

  public slots:

  void hovered(const QString & link, const QString & title, const QString & textContent) {
    this->statusBar()->showMessage(link == "" ?  defaultMessage : link);
  }

 private:
  QString defaultMessage;

};

#endif

Let me know if this helps.

Upvotes: 2

Related Questions