enthought / enthought/traitsui

Qt HTMLEditor does not open link when HTML/user gesture opening links externally

Open
#1,464 5 comments 0 reactions 0 assignees View on GitHub
component: core toolkit: Qt
Dominant language
Python
Stars
306
Forks
99
PR merge metrics
No merged PRs in 30d

Description

Qt WebKit/WebEngine supports opening a link in a new window when the HTML author instructs it to do so with `target='_blank'`:
```
Target to _blank Link
```
The user can also elect to open a link in a new window by selecting "Open Link in New Window" from the context menu.

Unexpected behaviour: HTMLEditor does not open the link at all for the above gestures.
Expected behaviour: HTMLEditor will honour the above gestures and allow the link to be open in a new window. What is a "new window" depends on the context. But given the existing behaviour of the `open_externally` flag on the HTMLEditor is to open a link in the user's machine default web browser, I'd expect that new window to mean the same.

To demonstrate with this example code:

Code snippet

```python

from traits.api import HasTraits, HTML
from traitsui.api import UItem, View, HTMLEditor

html = """

Target to default Link


Target to _blank Link

"""

class HTMLEditorDemo(HasTraits):

my_html_trait = HTML(html)

traits_view = View(
UItem(
'my_html_trait',
editor=HTMLEditor(format_text=True)
),
title='HTMLEditor',
buttons=['OK'],
width=800,
height=600,
resizable=True
)

# Create the demo:
demo = HTMLEditorDemo()

# Run the demo (if invoked from the command line):
if __name__ == '__main__':
demo.configure_traits()

```

This is the current behaviour (video is created using PySide2 + WebEngine, but PyQt5 + WebKit behaves in pretty much the same way except the "Back" option is not available from the context menu):

https://user-images.githubusercontent.com/3673984/103654983-89105080-4f5e-11eb-9182-1dac2d38a9e6.mp4

If I add `open_externally=True` to `HTMLEditor`, like this:
```
UItem(
'my_html_trait',
editor=HTMLEditor(format_text=True, open_externally=True)
),
```

Then all that changes is that the link is open in the default web browser when I click the link ~without `target='_blank'`~ (edited: this behaviour is different on PyQt5 and PySide2), gestures to explicitly open the link in a new window still results in the link not being opened at all:

https://user-images.githubusercontent.com/3673984/103655265-e5737000-4f5e-11eb-98c0-bf48e5559c31.mp4

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.