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. Handling mouseevent in Qstatusbar .

Handling mouseevent in Qstatusbar .

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 2.9k 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.
  • B Offline
    B Offline
    BibekKumar
    wrote on last edited by
    #1

    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
    0
    • S Offline
      S Offline
      Sam
      wrote on last edited by
      #2

      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
      0
      • B Offline
        B Offline
        BibekKumar
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lgeyer
          wrote on last edited by
          #4

          Subclass QLabel and reimplement mousePressEvent().

          1 Reply Last reply
          0
          • B Offline
            B Offline
            BibekKumar
            wrote on last edited by
            #5

            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
            0
            • L Offline
              L Offline
              lgeyer
              wrote on last edited by
              #6

              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
              0
              • B Offline
                B Offline
                BibekKumar
                wrote on last edited by
                #7

                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
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #8

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

                  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