简体   繁体   中英

QLabel setText() doesn't work in Event() function in Qt environment

there is a QLabel object named rightLabel in My Dialog, and when I click right button ,I want the rightLabel display "right Click OK.", but it doesn't work. Then the code is :

    bool MyDialog::event(QEvent *evt)
{
    if(evt->type()==QEvent::ContextMenu)
    {
        qDebug()<<"rightbutton";   //that's ok
        this->rightLabel->setText("Right Click OK");//doesn't work
    }
    ……

You should return QDialog::event(evt); and all will be good.

bool MyDialog::event(QEvent *evt)
{
    if(evt->type()==QEvent::ContextMenu)
    {
        qDebug()<<"rightbutton";   //that's ok
        this->rightLabel->setText("Right Click OK");//will work
    }
    //other if
    return QDialog::event(evt);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM