Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-4458

QLabel::linkHovered() not emitted and cursor may not change when hovering over link

    XMLWordPrintable

Details

    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()

      { static int count = 0; setText("<a href='test'>Link with same anchor</a>"); }

      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();
      }

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            hanssen Andreas Aardal Hanssen (closed Nokia identity) (Inactive)
            sthomass Stian Sandvik Thomassen (closed Nokia identity) (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes