Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] The tip message isn't shown up in QStatusBar ?
QtWS25 Last Chance

[SOLVED] The tip message isn't shown up in QStatusBar ?

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 3.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DiIvPa
    wrote on last edited by
    #1

    Dear Forumers, the menu item tips aren't shown up in QStatusBar but showMessage works properly. I cann't figure out where I am wrong. Could you please be so kind to help me ? Thank you in advance for any help and advices.
    //viral.cpp
    @
    #include "viral.h"

    viral::viral(QWidget *parent)
    : QWidget(parent) {
    setWindowTitle("Writeboard");
    edit = new QTextEdit();
    bar = new QMenuBar(this);
    status = new QStatusBar(this);

    menubar0 = new QMenu(this);
    menubar1 = new QMenu(this);

    bar -> setMinimumWidth(2);
    layout_V = new QVBoxLayout();
    //menu bar 0
    newFile = new QAction(("&New"),this);
    newFile -> setShortcuts(QKeySequence::New);
    newFile -> setStatusTip(tr("Create a new file"));
    connect(newFile,SIGNAL(triggered()),this,SLOT(newfile()));
    //menu bar 1
    mystatus = new QAction(("&Status Bar"), this);
    mystatus -> setCheckable(true);
    connect( mystatus, SIGNAL(toggled(bool)), status, SLOT(setHidden(bool)));

    menubar0 = bar -> addMenu(tr("&File"));
    menubar1 = bar -> addMenu(tr("&View"));

    menubar0 -> addAction(newFile);
    menubar1 -> addAction(mystatus);

    layout_V -> addWidget(bar);
    layout_V -> addWidget(edit);
    layout_V -> addWidget(status);
    setLayout(layout_V);
    showMaximized();
    }

    viral::~viral() {}

    void viral::newfile() {
    edit -> setPlainText("");
    mFilePath = "";
    status -> showMessage(tr("New File created"),3000);
    }
    @
    //viral.h
    @
    #ifndef VIRAL_H
    #define VIRAL_H

    #include <QApplication>
    #include <QtGui/QWidget>
    #include<QMenuBar>
    #include<QAction>
    #include<QTextEdit>
    #include<QVBoxLayout>
    #include<QMenu>
    #include<QStatusBar>
    #include<QFile>
    #include<QFileDialog>
    #include<QString>
    #include<QMessageBox>

    class viral : public QWidget
    {
    Q_OBJECT

    public:
    

    viral(QWidget *parent = 0);
    ~viral();

    private:

    QStatusBar *status;
    QTextEdit *edit;
    QMenu *menubar0;
    QMenu *menubar1;
    QMenuBar *bar;

    QAction *newFile;

    QAction *mystatus;

    QVBoxLayout *layout_V;

    private slots:

    void newfile();

    private:

    QString mFilePath;
    };

    #endif // VIRAL_H
    @
    //main.cpp
    @
    #include "viral.h"

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    viral w;
    w.show();
    return a.exec();
    }
    @

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You should add which Qt/OS combo you are using

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DiIvPa
        wrote on last edited by
        #3

        Hi, SGaist, thank you very much for quick reply. I am using LINUX Debian OS and Qt from distributive. Here it is :
        @

        qmake -v
        QMake version 2.01a
        Using Qt version 4.8.2 in /usr/lib/x86_64-linux-gnu
        @
        That's it.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          This one is a bit old, can you test if you have the same behavior with 4.8.6 ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • P Offline
            P Offline
            pmoglaikar
            wrote on last edited by
            #5

            Hi DiIvPa,

            SGaist : I guess this problem is not with Qt version but related with QMainWindow & QWidget.

            DiIvPa : If you check QMainWindow has statusBar() function which returns QStatusBar * and as per documentation setStatusTip(QString) will work on that perfectly.
            But if you try the same thing on QWidget you will not find statusBar() function as member of QWidget.

            Here is solution for your problem....
            Modified code as....
            @
            // ---- viral.cpp ---

            #include "viral.h"

            viral::viral(QWidget *parent)
            : QWidget(parent) {
            setWindowTitle("Writeboard");
            edit = new QTextEdit();
            bar = new QMenuBar(this);
            status = new QStatusBar(this);

            menubar0 = new QMenu(this);
            menubar1 = new QMenu(this);

            bar -> setMinimumWidth(2);
            layout_V = new QVBoxLayout();
            //menu bar 0
            newFile = new QAction(("&New"),this);
            newFile -> setShortcuts(QKeySequence::New);
            newFile -> setStatusTip(tr("Create a new file"));
            connect(newFile,SIGNAL(triggered()),this,SLOT(newfile()));

            //menu bar 1
            mystatus = new QAction(("&Status Bar"), this);
            mystatus -> setCheckable(true);
            mystatus->setStatusTip(tr("Status check box here..."));
            connect( mystatus, SIGNAL(toggled(bool)), status, SLOT(setHidden(bool)));
            connect( newFile, SIGNAL(hovered()), this, SLOT(newFileStatusMsg()));
            connect( mystatus, SIGNAL(hovered()), this, SLOT(myStatusMsg()));

            menubar0 = bar -> addMenu(tr("&File"));
            menubar1 = bar -> addMenu(tr("&View"));

            menubar0 -> addAction(newFile);
            menubar1 -> addAction(mystatus);

            layout_V -> addWidget(bar);
            layout_V -> addWidget(edit);
            layout_V -> addWidget(status);
            status->activateWindow();
            setLayout(layout_V);
            showMaximized();
            }

            viral::~viral() {}

            void viral::newFileStatusMsg()
            {
            QString qString1 = newFile->statusTip();
            QByteArray byteArray = qString1.toUtf8();
            const char* cString = byteArray.constData();
            status -> showMessage(tr(cString),3000);
            }

            void viral::myStatusMsg()
            {
            QString qString1 = mystatus->statusTip();
            QByteArray byteArray = qString1.toUtf8();
            const char* cString = byteArray.constData();
            status -> showMessage(tr(cString),3000);
            }

            void viral::newfile() {
            edit -> setPlainText("");
            mFilePath = "";
            status -> showMessage(tr("New File created"),3000);
            }


            // --- viral.h ---

            #ifndef VIRAL_H
            #define VIRAL_H
            #include <QApplication>

            #include<QMenuBar>
            #include<QAction>
            #include<QTextEdit>
            #include<QVBoxLayout>
            #include<QMenu>
            #include<QStatusBar>
            #include<QFile>
            #include<QFileDialog>
            #include<QString>
            #include<QMessageBox>

            class viral : public QWidget
            {
            Q_OBJECT

            public:
            

            viral(QWidget *parent = 0);
            ~viral();

            private:

            QStatusBar *status;
            QTextEdit *edit;
            QMenu *menubar0;
            QMenu *menubar1;
            QMenuBar *bar;

            QAction *newFile;

            QAction *mystatus;

            QVBoxLayout *layout_V;

            private slots:

            void newfile();
            void newFileStatusMsg();
            void myStatusMsg();

            private:

            QString mFilePath;
            };

            #endif // VIRAL_H


            // ---main.cpp ---

            #include "viral.h"
            #include <QApplication>

            int main(int argc, char *argv[])
            {
            QApplication a(argc, argv);
            viral w;
            w.show();

            return a.exec(&#41;;
            

            }
            @

            I have complied and run now it will work fine.... as you want... !

            Thanks
            Prashant

            [edit: corrected code formatting (one @ a the beginning and one at the end SGaist]

            1 Reply Last reply
            0
            • P Offline
              P Offline
              pmoglaikar
              wrote on last edited by
              #6

              Pardone me for the formatting of code....
              I will defintely take care from onwards...

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Good catch ! I've missed the wrong base widget

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  DiIvPa
                  wrote on last edited by
                  #8

                  Dear Prashant, SGaist, in some UI I used staus bar of QMainWindow and it works fine. Then I tryed to write separate widget with status bar and encounted problem with setStatusTip. I tryed really different CONNECT but wasn't successful (I tryed use the signal message Change and so on). Now I see that I need to define separate connections to every menu item. Not good but .... As to the Qt versions then I use the standard version from Debian distributive and to use "third party version" isn't a good practice. But I belive that the current version is modern enough because I didn't meet any discrepancy with manuals yet and so on...
                  Ok, I think that the problem could be considered as SOLVED. Thank you very much for help. I really appreciate it. My best wished and regards.

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    pmoglaikar
                    wrote on last edited by
                    #9

                    Your welcome....!

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved