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`s hyperlink tab order activation
Qt 6.11 is out! See what's new in the release blog

QLabel`s hyperlink tab order activation

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.0k 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.
  • meteoirM Offline
    meteoirM Offline
    meteoir
    wrote on last edited by A Former User
    #1

    Hello!
    I have small question about Tab Order on the form with qlabels. In my project I have some qlabels with hyperlinks inside (inserted with rich text editor in designer with html tags).
    I settings up focusPolicy property on qlabel and set it to "TabFocus". So, I have correct tab order with some controls with qlabels.
    But I need that on tab press hyperlink have been activated, not entire qlabel. Now qlabel focused first and after this hyperlink inside qlabel on next tab press.
    QLabels was setup like

    label->setTextInteractionFlags(Qt::LinksAccessibleByKeyboard | Qt::LinksAccessibleByMouse);

    How can I skip focus on QLabel and immediately focused on Hypertext inside that qlabel?
    Thx

    PS: I don`t know is that problem similar or not - but when I go to QToolButton with tab_key - it is not focused. QToolButton on form has stylesheet:

    QToolButton
    {
    	background: transparent;
    	border:none;
    }
    QToolButton:hover
    {
    	border: 1px solid blue;
    }
    QToolButton:focused, pressed
    {
    	border: 1px solid blue;
    }
    QToolButton:indicator
    {
    	border: 1px solid blue;
    }
    

    but when I go to this button with tab key - widget reacts on pressing by Space, but is not highlighted with border.
    Thx again

    [Edit: Added code tags -- @Wieland]

    1 Reply Last reply
    0
    • S Offline
      S Offline
      skirill
      wrote on last edited by skirill
      #2

      I realize it's an old post. Anyway. The way I did this is by installing an event filter for QLabel in question with

      ui->label->installEventFilter(this);
      

      then in

      bool MyDialog::eventFilter(QObject * _target, QEvent * _event)
      

      emulate tab click on FocusIn event for QLabel:

         if (_target == ui->label && _event->type() == QEvent::FocusIn) {
      //        focusNextChild();
             QKeyEvent *tab_key_press = new QKeyEvent(QKeyEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier);
             QApplication::sendEvent(_target, tab_key_press);
         }
      

      note that focusNextChild(); (commented out) does not help here, is skips QLabel altogether. Emulated tab click works.

      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