QTreeView 如何才能让一行的颜色充满整行?

aviramaxthon 2014-07-25 02:12:37
现在在用QTreeView写一个播放列表,遇到了这样一个问题:

我设置了整行选中以后发现QTreeView并不能选中每一行后面的空白的地方:

读了一下QTreeView的源代码,发现它只绘制了当前所有visible的Column,后面的就全无视掉了。于是想到了重写Delegate然后强行把宽度改成width(),但是因为使用了透明色,就会导致颜色从左到右一个一个深,这个方案就被抛弃了。

现在想到了添加一个空白的column然后使用拉伸最后一个column的办法,中间不断调整column的宽度,但是这个方法太2了,而且实现出来的效果特别差,闪烁离谱而且有时候还会失效。最后这个办法也被放弃了。
求各位大神们看看有没有什么办法?Qt新人还请多指教。
...全文
650 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
刀刀亮 2014-07-25
  • 打赏
  • 举报
回复
建议中间自适应内容,最后一行拉伸
dext 2014-07-25
  • 打赏
  • 举报
回复
这个难道 selectionMode 和 stretchLastSection 搞不定?

selectionMode : SelectionMode
This property holds which selection mode the view operates in.
This property controls whether the user can select one or many items and, in many-item selections, whether the selection must be a continuous range of items.
Access functions:
QAbstractItemView::SelectionMode selectionMode () const
void setSelectionMode ( QAbstractItemView::SelectionMode mode )

stretchLastSection : bool
This property holds whether the last visible section in the header takes up all the available space.
The default value is false.
Note: The horizontal headers provided by QTreeView are configured with this property set to true, ensuring that the view does not waste any of the space assigned to it for its header. If this value is set to true, this property will override the resize mode set on the last section in the header.
Access functions:
bool stretchLastSection () const
void setStretchLastSection ( bool stretch )
aviramaxthon 2014-07-25
  • 打赏
  • 举报
回复
引用 2 楼 xiaoliang_1 的回复:
建议中间自适应内容,最后一行拉伸
现在已经是中间自适应内容了,最后一行拉伸的话首先是排序的标志位置很奇葩,其次是如果此时增加一个Column显示起来会很蛋疼:最后已经拉伸过的Column宽度不变。
aviramaxthon 2014-07-25
  • 打赏
  • 举报
回复
引用 1 楼 dext 的回复:
这个难道 selectionMode 和 stretchLastSection 搞不定? selectionMode : SelectionMode This property holds which selection mode the view operates in. This property controls whether the user can select one or many items and, in many-item selections, whether the selection must be a continuous range of items. Access functions: QAbstractItemView::SelectionMode selectionMode () const void setSelectionMode ( QAbstractItemView::SelectionMode mode ) stretchLastSection : bool This property holds whether the last visible section in the header takes up all the available space. The default value is false. Note: The horizontal headers provided by QTreeView are configured with this property set to true, ensuring that the view does not waste any of the space assigned to it for its header. If this value is set to true, this property will override the resize mode set on the last section in the header. Access functions: bool stretchLastSection () const void setStretchLastSection ( bool stretch )
selectionMode已经设置完毕了,这个问题并不是由于这个造成的。在QTreeView源代码里的drawTree函数里,只绘制到了最后一个可以看到的Column之前的东西,后面的就没有管了。 stretchLastSection这个函数也用过。当Column多一行的时候,最后一行的宽度是不变的,这个也算是个bug了,而且最后一行拉伸会让UI显得极不自然。

16,787

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧