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
CodePudding user response:
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.