Details
-
Bug
-
Resolution: Invalid
-
Not Evaluated
-
4.5.0
-
None
Description
A QLabel's linkHovered() signal may not be emitted and its cursor may not change when hovering over a link.
The QTextControl used by QLabel only emits linkHovered() if the current anchor is different from the previous anchor, but the visible link in the QLabel may have changed while the anchor is the same. In this case the QLabel::linkHovered() siganl will not be emitted and its cursor will not change to the PointingHandCursor.
The following example demonstrates the problem. Hover over the initial link and see that the linkHovered() signal is emitted and the cursor changes. Click on the button to change the link (while its anchor remains the same) and move the cursor over the link again. This time the linkHovered() signal is not emitted and the cursor does not change.
#include <QtGui>
class Label : public QLabel
{
Q_OBJECT
public:
Label(const QString &text, QWidget *parent = 0) : QLabel(text, parent)
{
}
public slots:
void changeLink()
void printLinkHovered(const QString &anchor)
{ qDebug() << anchor; }};
#include "main.moc"
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QWidget w;
QVBoxLayout *vbl = new QVBoxLayout(&w);
QLabel *l = new Label("<a href='test'>Link</a>");
QPushButton *b = new QPushButton("Change label link");
vbl->addWidget(l);
vbl->addWidget(b);
l->setAutoFillBackground(true);
QPalette p = l->palette();
p.setColor(QPalette::Window, Qt::green);
l->setPalette(p);
QObject::connect(b, SIGNAL(clicked()), l, SLOT(changeLink()));
QObject::connect(l, SIGNAL(linkHovered(QString)), l, SLOT(printLinkHovered(QString)));
w.show();
return app.exec();
}