如何在 QT/PyQt 中创建带有可点击文本的小部件?

发布于 2024-08-30 07:30:19 字数 433 浏览 4 评论 0原文

我正在尝试实现不可编辑的 QTableView,其单元格中的小部件应包含可单击的列出文本。使用以下代码,我在确定的单元格中设置小部件:

view = QTableView()
label = QLabel( <some html text> )
...
view.setIndexWidget(index, label)

我使用 html 使标签的文本可点击,但链接变成蓝色并带有下划线,此外,用鼠标右键单击它会出现带有“复制链接位置”选项的弹出菜单,其中我想要放置一些隐藏信息而不是 url,当然不要让用户看到此信息。

我正在寻找轻量级小部件,我认为在每个单元格中插入 QGraphicsView 会导致大量计算机负载,但想不出任何其他解决方案。

你能建议我应该用什么来达到这个目的吗?

提前谢谢你

谢尔盖

i'm trying to realize non-editable QTableView with widgets in cells that should contain clickable listed text. With following code i'm setting widget in definite cell:

view = QTableView()
label = QLabel( <some html text> )
...
view.setIndexWidget(index, label)

I used html to make label's text clickable, but links became blue with underline and moreover by clicking on it with right mouse button appears popup menu with "Copy Link Locaion" option, where i wanted to place some hidden information instead of url and of course do not let user see this info.

I'm looking for light-weight widget, i thought that insertion of QGraphicsView in each cell will lead to big computer loads, but can't think of any other solution.

Can you advice what should i use for this purpose?

Thank you in advance

Serge

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无法回应 2024-09-06 07:30:19

使用 QTextBrowser 小部件而不是 QLabel 。

Use the QTextBrowser widget instead of QLabel.

微暖i 2024-09-06 07:30:19

当我在文档中看到支持的标签时,我感到很困惑,这些标签甚至没有尝试检查 QLabel 中支持的样式。所以我用以下方法解决了这个问题:

self.setContextMenuPolicy(Qt.PreventContextMenu)
...
str = "<qt><style>a.class1 { color: black; text-decoration: none; }</style>"
str += "<a href='" + <hiden_value> + "' class='class1'>" + <value> + "</a>" 

I get myself confused when i saw in documentation supported tags, that haven't even tried to check styles supporting in QLabel. So I've solved it with following:

self.setContextMenuPolicy(Qt.PreventContextMenu)
...
str = "<qt><style>a.class1 { color: black; text-decoration: none; }</style>"
str += "<a href='" + <hiden_value> + "' class='class1'>" + <value> + "</a>" 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文