Meet problem when use "QTreeWidgetItem::DontShowIndicator"
-
when I use setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicator) with a node, then the node's children can't be shown, collapse/expand can't be used, but I just want minus/plus sign dont show.
@
TreeWidgetItem *root=tree->invisibleRootItem();
myDeviceItem = new QTreeWidgetItem(root);
myDeviceItem->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicator);
myDeviceItem->setText(0,"My Devices");
myDeviceItem->setIcon(0,QIcon(":/icons/house.ico"));publishItem = new QTreeWidgetItem(myDeviceItem); publishItem->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicator); publishItem->setText(0,"Publish"); publishItem->setIcon(0,QIcon(":/icons/right.ico")); subscribeItem = new QTreeWidgetItem(myDeviceItem); subscribeItem->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicator); subscribeItem->setText(0,"Subscribe"); subscribeItem->setIcon(0,QIcon(":/icons/left.ico"));
@
Edit: Please wrap your code in @ tags; mlong
-
Instead of using setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicator), you can try modifying the drawing of the branches to not draw the minus/plus sign in the style by reimplementing "drawPrimitive()":http://doc.qt.nokia.com/4.7/qstyle.html#drawPrimitive and modifying the "QStyle::PE_IndicatorBranch":http://doc.qt.nokia.com/4.7/qstyle.html#PrimitiveElement-enum element. Does doing so help?
-
Thanks,sigrid, I define a class inheriting QWindowsStyle,and then reimplement its drawPrimitive() as below:
@void IndicatorNoneStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter p, const QWidget w) const
{
QStyleOption op = const_cast<QStyleOption>(opt);
op->state &= ~ QStyle::State_Children;
QWindowsStyle::drawPrimitive(pe, op, p, w);
}@
that works correctly. cool you are