QTreeWidget 根据内容设置每行的高度 [英] QTreeWidget set height of each row depending on content

查看:160
本文介绍了QTreeWidget 根据内容设置每行的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 QTreeWidget 中制作具有多行内容的可编辑单元格,为此我使用 QPlainTextEdit 作为委托.我需要为所有行设置适当的大小,以便在编辑和显示之间切换顺畅,没有任何可见的变化.

I want to make editable cells with multi-lines content in QTreeWidget and I use for this purpose QPlainTextEdit as a delegate. I need to set proper size to all rows that switching between editing and displaying went smooth, without any visible changes.

rect = textEdit.blockBoundingRect(textEdit.firstVisibleBlock())

  • 有了这个,我可以找出我需要为行设置的高度,但我错过了我可以做到的地方.
  • 如何在初始化阶段为 QTreeWidget 的行设置适当的高度以及如何处理它的变化?

    How can I set proper height to QTreeWidget's rows on initialization stage and how to handle it's changes?

    推荐答案

    您需要重新实现委托的 sizeHint().它将自动处理行的高度和宽度.请注意,在这种情况下,QTreeWidget::uniformRowHeight 属性必须为 false,但如果它包含许多行,它会减慢树元素的渲染.

    You need to reimplement delegate's sizeHint(). It will automatically handle row's height and width. And note, that QTreeWidget::uniformRowHeight property must be false in this case, though it will slow tree element rendering if it contains many rows.

    这篇关于QTreeWidget 根据内容设置每行的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆