简体   繁体   中英

QTreeWidget expand sign

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

QTreeWidgetItems have the property childIndicatorPolicy . The allowed values are:

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

You want the first one.

theItem.setChildIndicatorPolicy(QTreeWidgetItem.ShowIndicator)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM