Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Handling mouseevent in Qstatusbar .

    General and Desktop
    4
    8
    2515
    Loading More Posts
    • 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.
    • B
      BibekKumar last edited by

      In my statusbar , i have added one Qlabel inside which i am displaying some message . Now what i want is when i click on that Qlabel(present inside the Qstatusbar ) , the message should disappear ..

      I have added the label inside statusbar as follows ,

             @QLabel *cpyrightlbl= new QLabel();
      

      ui.statusBar->addWidget(cpyrightlbl);
      cpyrightlbl->setText("Demo Message");
      cpyrightlbl->setWindowFlags( Qt::FramelessWindowHint );
      cpyrightlbl->setStyleSheet("border: 3px");
      cpyrightlbl->setFixedWidth(frameGeometry().width());
      cpyrightlbl->show();@

      1 Reply Last reply Reply Quote 0
      • S
        Sam last edited by

        Why do you want to use a mouseClick on the status bar message.. You can also dispay the message for a particular time interval and it will disappear after timeout.

        check "this":http://qt-project.org/forums/viewthread/17192/

        1 Reply Last reply Reply Quote 0
        • B
          BibekKumar last edited by

          Actually the requirement is unless the user clcik on that label , the message shall be displayed .

          1 Reply Last reply Reply Quote 0
          • L
            lgeyer last edited by

            Subclass QLabel and reimplement mousePressEvent().

            1 Reply Last reply Reply Quote 0
            • B
              BibekKumar last edited by

              i have done as u said above , but it has no impact ..

              Here i am mentioning my code

              inside display.h

              @#ifndef MSGDISPLAY_H
              #define MSGDISPLAY_H

              #include <QLabel>

              class MsgDisplay : public QLabel
              {
              Q_OBJECT
              public:
              MsgDisplay(QWidget *parent = 0);
              ~MsgDisplay();
              void setMessage(QString str);
              protected:
              virtual void mousePressEvent(QMouseEvent * event);
              };

              #endif // MSGDISPLAY_H

              inside display.cpp

              #include "MsgDisplay.h"

              MsgDisplay::MsgDisplay(QWidget *parent)
              : QLabel(parent)
              {

              }
              void MsgDisplay::setMessage(QString str)
              {
              setText("<font color='Blue'>Demo Message<font>");
              QFont font;
              font.setPointSize(10);
              font.setBold(true);
              setFont(font);

              }
              MsgDisplay::~MsgDisplay()
              {

              }
              void MsgDisplay::mousePressEvent(QMouseEvent * event)
              {
              hide();
              }

              inside Myclass.cpp

              #include display.h

              void Myclass::Label()
              {
              MsgDisplay *statusLabel = new MsgDisplay();
              ui.statusBar->addWidget(statusLabel);
              statusLabel->setMessage(QString("hi"));
              }@

              1 Reply Last reply Reply Quote 0
              • L
                lgeyer last edited by

                The code you've posted should work as expected (at least when it comes to the requested functionality). Can you provide a small, compilable example which reproduces the problem?

                1 Reply Last reply Reply Quote 0
                • B
                  BibekKumar last edited by

                  I got the solution for the above one ..
                  Now i am running through one more problem i.e when i minimize my main application window the status bar message is getting truncated . Is there any way to resolve this issue ? I mean to say the same message shall be displayed without any trucation during minimizing and maximizing .

                  1 Reply Last reply Reply Quote 0
                  • A
                    andre last edited by

                    How do you imagine to display anything on a minimized application window?

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post