Making QLabel behave like a hyperlink

前端 未结 2 977
名媛妹妹
名媛妹妹 2020-12-14 06:30

how can I make a QLabel to behave like a link? What I mean is that I\'d like to be able to click on it and then this would invoke some command on it.

2条回答
  •  囚心锁ツ
    2020-12-14 06:59

    QLabel does this already.

    Sample code:

    myLabel->setText("Click Here!");
    myLabel->setTextFormat(Qt::RichText);
    myLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
    myLabel->setOpenExternalLinks(true);
    

提交回复
热议问题