html转word QT,python - Word Wrapping Qt Qlabel text in a HTML <td> element - Stack Overflow

Intro:

I am trying to draw paginated forum posts in QT. Some of my initial efforts resulted in a QFrame with nested labels (a screenshot is shown here). Since then I have had to intermix quotes with regular text and I need dynamic labels to do that in my current approach(i.e., a post instance may have 5 quotes and 7 regular text = 13 QLabels, and each time I draw a new post instance I recreate all the QLabels). Creating and destroying QLabels is quite expensive and I see a visual lag.

So I have decided to try and do it in a single QLabel using HTML. I chose the approach outlined here to seperate the post meta data and the post body using a emulated vertical line.

The vertical line works fine, however I can't get the post body to text wrap. I have a suspicion that QT's html engine is going to be tricky to coerce, and I am not a HTML guru.

Question:

How do I get the following code to word wrap to a fixed width (i.e., vertical growth).

from PyQt4.QtGui import QApplication, QLabel

import sys

html = '''

#%s

User: %s

posted at: %s

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.

''' % (1, "hassan", "sunday")

app = QApplication(sys.argv)

l = QLabel(html)

l.show()

app.exec_()

sys.exit()

Which results in :

Yo10U.png

Note: width is not being respected as well as no word wrap.

Oh and if you want to show off, feel free to style the post and show a quoted area as well :D

edit:

I tried altering the post body widget (instead of alterin the entire widget), it's a QVBoxLayout with QLabels. I altered it to a single QLabel with

and

. And that combo does linewrap properly. Though even with that working ok, the layout + label approach looks nicer.

So perhaps I should ammend my design and maintain a list of Quote Widgets + regular text labels, in order to get rid of visual lag via recyling.

Still if someone can create and style a sensible html representation of a forum post from the code above it is probably a more robust solution.

edit 2:

Whilst it might be possible to get HTML based styling to work off a single QLabel in my case, after trying to get it working I have come to the conclusion that a multi QLabel approach lays things out in a more controlled fashion, without much effort on my part. I'll stick to this.

/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值