QTreeWidget expand sign

匿名 (未验证) 提交于 2019-12-03 02:30:02

问题:

How to make expandable sign in QTreeWidget always visible even when item doest have any subitems? And how to draw something else instead of default sign?

Thanks in advance, Serge

回答1:

QTreeWidgetItems have the property childIndicatorPolicy. The allowed values are:

  • QTreeWidgetItem::ShowIndicator
  • QTreeWidgetItem::DontShowIndicator
  • QTreeWidgetItem::DontShowIndicatorWhenChildless

You want the first one.

theItem.setChildIndicatorPolicy(QTreeWidgetItem.ShowIndicator)


回答2:

Answering on my second part of question for others.

I looked for drawing functions in QTreeView and found following:

void QTreeView::drawBranches ( QPainter * painter, const QRect & rect, const QModelIndex & index ) 

With this function you can draw whatever you want at the left side of each item.

And another good choice to hanlde this - use Style Sheets for QTreeView:

http://qt.nokia.com/doc/4.6/stylesheet-examples.html#customizing-qtreeview



转载请标明出处:QTreeWidget expand sign
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!