Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Using text label as pushbutton



  • How to use text label as pushbutton.
    i just want to use the text that can be clicked.
    Thanks.



  • This post is deleted!


  • The QWidget base is not overfilled with signals compared with other widget-tool (.net VCL). I missed that feature too. You can install a eventfilter to catch all events, but this is no a comfortable reusable way.

    I have made my own Widgets by subclassing of nearly all standard QWidgets to enhance its features. In a QLabel subclass you can overwrite the mousePressEvent and the mouseReleaseEvent an make you own signals. Here example code

    //=======================================================================
    void AdvLabel::mouseReleaseEvent(QMouseEvent * event)
    //=======================================================================
    {
        if (!this->rect().contains(event->pos()))
        {
            QLabel::mouseReleaseEvent(event);
            return;
        }
        switch(event->button())
        {
            case Qt::LeftButton:   emit clicked(); break;
            case Qt::RightButton:  emit clickedRight(); break;
        }
        QLabel::mouseReleaseEvent(event);
     }
    
    

  • Lifetime Qt Champion

    Hi,

    Do you want to be able to click on it like a link or do you want a real button ? If the later, why not use a button ?



  • @SGaist
    I want to click on the text like a link .


  • Lifetime Qt Champion

    Something like provided by the openExternalLinks property ?


Log in to reply