Design page for task: "Add support for displaying clickable hyperlinks in the tabular view ".
- Started: Jstaniek October 2012
- Wish #308838
- Target: ?
- Status: In Progress, Assigned to Roman Shtemberko
It should be possible to display a clickable hyperlinks based on data from a text field in the tabular view.
The links should be displayed as underlined with default hyperlink style. This applies also to local paths.
Below are propositions by Roman Shtemberko.
Links can be detected by searching the text of the cell for some patterns, e.g. "http::/" and "https://" followed by some symbols/numbers for hyperlinks. RegEx can be used (see 6th milestone here ).
Local paths can be more trickier: for Unix-likes it will probably be '/' at the begging, Windows - "::\" preceded by some letter (disk name). I haven't found any RegEx for that yet.
Alternatively we can make links/paths to follow some pattern, like:
[link text](link itself)
Also we can use QLabels with Rich Text support for each of the cells.
Where to perform detection
1) We can perform checks just when we need them, i.e. on text rendering.
2) We can perform checks once text is loaded and after it's edited. This will require some more tweaking for the each text cell to store something like hasHyperlink. Also we might want to store different parts of text that is/is not hyperlink (see Text Rendering).
1) Use QPainter::drawText() to draw hyperlinks (font - blue, underlined). In this case we will need to successively draw each part of the text, e.g. text-link-text-link depending on how plain text is mixed with hyperlinks in the cell.
2) Use the same approach as in 1, but draw hyperlinks as QLabels (QWidget::render()).
As double-click on the cell is reserved for editing, I would assume we need context menu option for opening links.
No more guesses so far.
See also Forms/Button hyperlinks.