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

QLabel signal linkHovered



  • I'm connecting to both linkActivated and linkHovered. When I move the mouse over a label that has a link I see the debug output from the slot connected to the linkHovered signal once and once only, if I move out of the label and away, then hover over the label again I do not see any further signals raised or at least I don't see any debug output from the linkHovered slot.

    My slot is very simple it only contains a single debug output message. Is this behaviour a bug or is this how it currently works?

    I would expect there to be another signal to fire when moving out of the label but it appears not.

    This is my code which connects both linkActivated and linkHovered signals to slots in script:

            if ( strSignal.compare(clsQtLabel::mscszQtSignalLinkActivated) == 0 ) {
                cnSignal = QObject::connect(this
                                ,&clsQtLabel::linkActivated
                                ,[pobjScriptEng, strCall, strFile, strScript]() {
                                    QString strScriptWithCall = static_cast<QString>(strScript)
                                                              + static_cast<QString>(strCall) + "();";
                                    pobjScriptEng->evaluate(strScriptWithCall);
                                });
            } else if ( strSignal.compare(clsQtLabel::mscszQtSignalLinkHovered) == 0 ) {
                cnSignal = QObject::connect(this
                                ,&clsQtLabel::linkHovered
                                ,[pobjScriptEng, strCall, strFile, strScript]() {
                                    QString strScriptWithCall = static_cast<QString>(strScript)
                                                              + static_cast<QString>(strCall) + "();";
                                    pobjScriptEng->evaluate(strScriptWithCall);
                                });
            }
    

    I have break points in handlers on lines:

        pobjScriptEng->evaluate(strScriptWithCall);
    

    The parameter strScriptWithCall contains the full script ending with a call to the slot, I've verified that its content is correct.

    Another stranger problem is that although the "linkActivated" signal launches an instance of a browser with the link address correct and showing in the browser, the slot I've attached to the signal is not being called.


  • Moderators

    @SPlatten well looking at the source code

            if (interactionFlags & Qt::LinksAccessibleByMouse) {
    	        QString anchor = q->anchorAt(mousePos);
    	        if (anchor != highlightedAnchor) {
    	                highlightedAnchor = anchor;
                            emit q->linkHovered(anchor);
                    }
            }
    

    seems like the signal will fire again, when you hover over an other link but not when you hover again over the same link.

    Looks like intended behavior



  • @J-Hilk , Thank you, but surely if this is intended behaviour then its wrong, as this isn't how events like hover work in other environments including browsers. When the mouse moves over an element the hover should fire, when it moves out it should be cleared and then moving onto it again should trigger another signal.

    Is there anyway for me to trigger some kind of reset that will allow it to trigger again?


  • Moderators

    @SPlatten will this is part of the QWidgetTextControlPrivate class, therefore not accessible from outside.

    You can change the source code and compile the widgets module, that should work.

    Also reporting this to https://bugreports.qt.io is probably a good idea too



  • @J-Hilk , Thanks again, I'll raise it now.


  • Moderators

    @SPlatten When you do, post a link here so we/others can follow the ticket as well



  • @J-Hilk , done, I'm not sure if what I've supplied is adequate?

    https://bugreports.qt.io/browse/QTBUG-85246


  • Moderators

    @SPlatten sounds good enough,

    If you have/can, supply a minimal example, usually gets a long way and can speed up the process :D



  • @J-Hilk , done.


Log in to reply