如何使用 QGraphicsWebView?
我想在委托内使用 QGraphicWebView 来渲染 QTableView 单元格,但我只是不知道如何处理 Paint() 方法所需的 QStyleOptionGraphicsItem 参数。如何构建它/我应该在哪里检索它? 我正在使用此代码作为参考,所以paint()方法应该是这样的:
def paint(self, painter, option, index):
web = QGraphicsWebView()
web.setHtml(some_html_text)
web.page().viewportSize().setWidth(option.rect.width())
painter.save()
painter.translate(option.rect.topLeft());
painter.setClipRect(option.rect.translated(-option.rect.topLeft()))
web.paint(painter, ??????) # what here?
painter.restore()
有什么建议吗?
I want to use a QGraphicWebView inside a delegate to render a QTableView cell, but I just don't know what to do with the QStyleOptionGraphicsItem parameter the paint() method requires. How to build it up / where should I retrieve it?
I'm using this code as reference, so the paint() method should be something like this:
def paint(self, painter, option, index):
web = QGraphicsWebView()
web.setHtml(some_html_text)
web.page().viewportSize().setWidth(option.rect.width())
painter.save()
painter.translate(option.rect.topLeft());
painter.setClipRect(option.rect.translated(-option.rect.topLeft()))
web.paint(painter, ??????) # what here?
painter.restore()
Any advice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您并不真正需要
QGraphicsWebView
并且QWebView
就足够了。请务必记住,您不需要自己调用
QWidget::paintEvent()
。考虑到这一限制,您将需要使用一个辅助类,该类可以在绘画设备上渲染或使用给定的画家进行渲染。 QWebFrame 有一个这样的方法,其形式为 渲染函数。根据您链接到的示例,以下内容应该有效:I'll assume that you don't really need
QGraphicsWebView
and thatQWebView
is sufficient.It's important to keep in mind that you're not expected to call
QWidget::paintEvent()
yourself. Given that constraint, you'll want to use a helper class that can render on a paint device or render using a given painter. QWebFrame has one such method in the form of its render function. Based off of your linked-to example, the following should work: