Handling mouseevent in Qstatusbar .

  • 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();

    cpyrightlbl->setText("Demo Message");
    cpyrightlbl->setWindowFlags( Qt::FramelessWindowHint );
    cpyrightlbl->setStyleSheet("border: 3px");

  • 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/

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

  • Subclass QLabel and reimplement mousePressEvent().

  • 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
    MsgDisplay(QWidget *parent = 0);
    void setMessage(QString str);
    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;


    void MsgDisplay::mousePressEvent(QMouseEvent * event)

    inside Myclass.cpp

    #include display.h

    void Myclass::Label()
    MsgDisplay *statusLabel = new MsgDisplay();

  • 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?

  • 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 .

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

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.