Nominate our 2022 Qt Champions!

QLabel - mouseReleaseEvent to parent - HTML label

  • Hi,

    I have a subclass of QDialog (called CDialog) that has a member of type: QLabel m_Text;

    CDialog has mouseReleaseEvent() where it detects if the user right or left clicks the dialog.

    My QLabel has this set:

    this->m_Text.setText("This is a sample text");

    If I do:


    Everything works fine. If I click on the text, it still relays the signal to the parent (so I catch the event).

    But if I do:


    The signal never gets relayed up to the parent. Somehow, if it's HTML, the QLabel catches the signal and blocks it. I can still press under/above the text string, and my CDialog will get the signal.
    I'm guessins this is because it scans for <a>-tags?

    I've tried:


    But that did little to nothing (saw it on another forum).

    So, how can I tell QLabel to always send the signal upwards - even if it's RichText?

    Thanks in advance.

    Best regards,

  • I really have no idea about this, but you might be able to accomplish this by inheriting QLabel and reimplementing mouseReleaseEvent. Some thoughts are to possibly use QMouseEvent::ignore(), QCoreApplication::sendEvent(), or QCoreApplication::postEvent(). As I said, I don't really know; It's just a thought.

  • Hi JordanHarris,

    Thanks for your response!

    I thought so too - but I really want to avoid making yet another subclass, I was hoping that there would be some sort of flag or setting that I've missed that could essentially solve this.

    But if there is none, then I'll have to make a new class inheriting it.

    Thanks for your thoughts, though :)

    Best regards,

  • Lifetime Qt Champion

    I tried a default project with a dialog and a label using rich text.

    I could not get it to steal the clicks.
    Dialog always got the click.

    So I wonder, besides setting

    do you do anything else to make this happen?

  • Hi @mrjj

    Thank you for taking time and checking this.

    That is weird indeed. This is how I setup my dialog (this being my CDialog : public QDialog)

    		QString message = "This is a sample text";
    		m_Text.setStyleSheet("QLabel#label_NotificationText { color: #DDDDDD; }");

    Then I have this function to capture the clicks:

    void mouseReleaseEvent ( QMouseEvent * event ) {
    	if(event->button() == Qt::RightButton) {
    	else if(event->button() == Qt::LeftButton) {
    		// Call the function we wanted
    		emit onNotificationPressed(this);

    Which never gets called if I press the QLabel m_Text (if it's HTML-enabled).

    I don't know if this matters, but I show the dialog using ->show();

    Best regards,

  • Lifetime Qt Champion

    That helped a lot - I could reproduce it.

    You can disable it with

    You might need to set some flags if u need copy paste etc.
    This completely removes any interaction.

  • @mrjj

    Wow, super. That actually solved it.

    Thank you so much for your response, your time and your help. I really appreciate it.


    Best regards,