1

TThe issue is I have a QLabel and I want users to select the text from it via keyboard or mouse and be able to get the context menu for "Copy", "Select All" etc. So I set the interactionFlags

QLabel::setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard)

but the issue is, as soon as I set these flags, the label is not focusable by keyboard. i.e user cannot navigate to the label via keyboard but however can select the label by mouse. This is critical for Accessibility users who are using Narrator to navigate to the label via keyboard.

Can someone please help me with this? I want to keep the flags while making sure its keyboard focusable.

Thank you

Gurushant
  • 952
  • 6
  • 23

1 Answers1

1

According to the Qt docs, you can't have it both ways. Either the label text is accessible by the keyboard like it is when you use "Select All", or the label is capable of keyboard focus.

Source:

If the flags contain Qt::LinksAccessibleByKeyboard the focus policy is also automatically set to Qt::StrongFocus. If Qt::TextSelectableByKeyboard is set then the focus policy is set to Qt::ClickFocus.

link

Alexander
  • 16,091
  • 5
  • 13
  • 29
  • 1
    @Gurushant I didn't know that was the case until just now. You can still implement copy and paste functionality on the labels while remaining keyboard focusable. The select all I am not so sure about though – Alexander Jul 15 '22 at 05:16