[Solved] Disable context menu for particular hyperlink in QMessageBox
-
Hello.
I showing QMessagebox which contains some text and two hyperlinks. Qt automatically adds context menu for those hyperlinks with command "Copy link location". My goal is to disable appearance of context menu for first hyperlink and keep it work for second hyperlink. How to do it? Thanks.
Qt version = 5.2.1, OS = Windows 8.1
-
Hi,
It would be pretty convoluted to achieve what you want with QMessageBox. You should rather create your own dialog for that.
Note that your users may get confused as to why one link works and not the other.
-
Hello.
Thank you for answer. I got it. No easy solution here. Ok I will write here some information about my solution and mark thread as "[Solved]".The link which shouldn't work is internal link (link to window of the program), so it's textual representation doesn't have any sense for user.
-
If it doesn't have any sense for the user then why show it that way ?
-
Oops. Looks like I didn't explain it very well. In the code link looks like "<a href='specurl://window2'>window</a>". To make it work I use QDesktopServices::setUrlHandler. So the link itself is useful, but the text "specurl://window2" is useless, because it can't be used in the program or in any other program. This is the reason to disable ability to copy link to clipboard.
-
Didn't you create an url handler for "specurl"?
-
Ok, I see what misguided me.
Then again, I don't see any easy solution except making your own dialog
-
I managed to disable context menu using a trick. Message was splitted into paragraphs. 1st paragraph contains 1st hyperlink, 2nd paragraph contains 2nd hyperlink. Then I manually added 2nd paragraph into QMessageBox's layout as QLabel with disabled context menu.
-
I managed to disable context menu using a trick. Message was splitted into paragraphs. 1st paragraph contains 1st hyperlink, 2nd paragraph contains 2nd hyperlink. Then I manually added 2nd paragraph into QMessageBox's layout as QLabel with disabled context menu.
-
Sounds good, thanks for sharing your idea !
-
Sounds good, thanks for sharing your idea !