Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QLabel - mouseReleaseEvent to parent - HTML label
QtWS25 Last Chance

QLabel - mouseReleaseEvent to parent - HTML label

Scheduled Pinned Locked Moved Solved General and Desktop
qlabelmouseeventhtml
7 Posts 3 Posters 3.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • antonlindgrenA Offline
    antonlindgrenA Offline
    antonlindgren
    wrote on last edited by antonlindgren
    #1

    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:

    
    this->m_Text.setTextFormat(Qt::PlainText);
    

    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:

    this->m_Text.setTextFormat(Qt::RichText);
    

    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:

    this->m_Text.setOpenExternalLinks(false);
    

    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,
    Anton

    1 Reply Last reply
    0
    • J Offline
      J Offline
      JordanHarris
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • antonlindgrenA Offline
        antonlindgrenA Offline
        antonlindgren
        wrote on last edited by
        #3

        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,
        Anton

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi
          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
          setTextFormat(Qt::RichText);

          do you do anything else to make this happen?

          1 Reply Last reply
          0
          • antonlindgrenA Offline
            antonlindgrenA Offline
            antonlindgren
            wrote on last edited by antonlindgren
            #5

            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";
            		this->setModal(false);
            		this->setWindowFlags(Qt::FramelessWindowHint|Qt::SplashScreen|Qt::WindowStaysOnTopHint);
            
            		m_Text.setObjectName("label_NotificationText");
            		m_Text.setStyleSheet("QLabel#label_NotificationText { color: #DDDDDD; }");
            		m_Text.setWordWrap(true);
            		m_Text.setText(message);
            		m_Text.setParent(this);
            		//m_Text.setTextFormat(Qt::RichText);
            

            Then I have this function to capture the clicks:

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

            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,
            Anton

            1 Reply Last reply
            1
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Super
              That helped a lot - I could reproduce it.

              You can disable it with
              m_Text.setTextInteractionFlags(Qt::NoTextInteraction);

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

              antonlindgrenA 1 Reply Last reply
              1
              • mrjjM mrjj

                Super
                That helped a lot - I could reproduce it.

                You can disable it with
                m_Text.setTextInteractionFlags(Qt::NoTextInteraction);

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

                antonlindgrenA Offline
                antonlindgrenA Offline
                antonlindgren
                wrote on last edited by
                #7

                @mrjj

                Wow, super. That actually solved it.

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

                Thanks.

                Best regards,
                Anton

                1 Reply Last reply
                1

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved