How to make a QGraphicsTextItem clickable?

一曲冷凌霜 提交于 2019-12-11 06:56:05

问题


In the "About box" of my software, I used a QGraphicsTextItem to show the about-text.

This text contains hypertext links (in the form of: <a href="http://some.random.site">link</a>).

The item shows up properly (hypertext links are blue and underlined). However, when I click on them, nothing happens.

Here is how I created the QGraphicsTextItem:

d_about_text_item = new QGraphicsTextItem;
d_about_text_item->setTextInteractionFlags(Qt::TextBrowserInteraction);
d_about_text_item->setHtml(aboutText());

As I understand the Qt documentation, the call to setTextInteractionFlags should allow me to handle special hypertext links click events.

Is there anything else I should do to be able to click on the links and show up the linked page in the default system browser ?


回答1:


I found what I did wrong:

My containing QGraphicsView had setInteractive() set to false. I removed it and since now, it works fine.




回答2:


FWIW I use the standard QMessageBox::about method and simply pass raw HTML as the text - links work fine.

QMessageBox::about(this, tr("About"), tr("<h1>My App</h1><p><a href='www.stackoverflow.com'>Click me!</a></p>"));


来源:https://stackoverflow.com/questions/3624733/how-to-make-a-qgraphicstextitem-clickable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!