2011-10-10 73 views
2

我有一個應用程序使用QTextBrowser控件在離線狀態下顯示網站,主要由「相對」鏈接組成。QTextBrowser - 覆蓋「複製鏈接位置」的上下文菜單快捷方式

不幸的是,QTextBrowser「複製鏈接位置」操作的默認上下文菜單將相關鏈接放入剪貼板。

我想攔截「複製鏈接位置」操作,因此我可以將相對路徑擴展到剪貼板上的絕對路徑,以便用戶可以直接粘貼到他們的文件管理器或另一個「打開文件」對話框中應用。

我知道如何將其他操作添加到上下文菜單,或完全替換上下文菜單。然而,其餘的默認菜單是好的,所以我寧願不這樣做,如果可能的話。

(目前使用Qt v4.6.2,可在必要時升級。)

回答

1

從Qt的助理文檔

無效QTextBrowser :: anchorClicked(常量QUrl &鏈接)[信號]

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. 

我發現這個在Qt4.6.0的幫助,所以它應該在你的版本

+0

我不是在討論anchorClicked()。 當鏈接被激活時(通常通過左鍵單擊它,但不一定),錨點信號發生,並且是一種導航頁面的方法。 我想重寫右鍵單擊鏈接時獲得的上下文菜單中的一個操作。 – Richard

+0

您可能需要重寫 'mousePressEvent(QMouseEvent * e)' – crazyjul