开发者

QTextBrowser - Override "Copy Link Location" context menu shortcut

开发者 https://www.devze.com 2023-04-12 11:50 出处:网络
I have an application that uses a Q开发者_运维知识库TextBrowser control to display a website while offline, which is primarily made up of \'relative\' links.

I have an application that uses a Q开发者_运维知识库TextBrowser control to display a website while offline, which is primarily made up of 'relative' links.

Unfortunately, the default context menu for the QTextBrowser "Copy Link Location" action puts the relative link into the clipboard.

I want to intercept that "Copy Link Location" action somehow so I can expand the relative path into the absolute path on the clipboard, so the user can then paste directly into their file manager or "Open file" dialog of another application.

I know how to add additional actions to the context menu, or replace the context menu entirely. However the rest of the default menu is fine so I would prefer not to do that if it is possible.

(Currently using Qt v4.6.2, can upgrade if necessary.)


From Qt assistant documentation

void QTextBrowser::anchorClicked ( const QUrl & link ) [signal]

This signal is emitted when the user clicks an anchor. The URL referred to by the anchor
is passed in link.

Note that the browser will automatically handle navigation to the location specified by
link unless the openLinks property is set to false or you call setSource() in a slot 
connected. This mechanism is used to override the default navigation features of
the browser.

I've found this in Qt4.6.0 help, so it should work in your version

0

精彩评论

暂无评论...
验证码 换一张
取 消