QTreeWidget 节点选中的图标怎么设置
2个回答
2017-02-11 · 知道合伙人互联网行家
关注
展开全部
修改tree节点的图标的步骤如下:
首先,在src下建立一个assets文件夹,放几张图片;
其次,编写代码如下:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" fontSize="14" layout="absolute">
<mx:Script>
<![CDATA[
[Embed(source="assets/boy.jpg")]
public var boyIcon:Class;
[Embed(source="assets/girl.jpg")]
public var girlIcon:Class;
// 根据结点的属性设置节点图标
private function SetIcon(item:Object):*
{
var xml:XML = item as XML;
if(xml.attribute("sex")=="boy")
{
return boyIcon;
}
else
{
return girlIcon; }
}
// Tree控件的数据源
[Bindable]
public var departmentTree:XML=
<member name="小李" sex="boy">
<member name="王志" sex="boy">
<member name="赵强" sex="boy" />
<member name="李丽" sex="girl" />
</member>
<member name="韩梅梅" sex="girl">
<member name="孙艳" sex="girl"/>
</member>
</member>
]]>
</mx:Script>
<mx:Tree x="216" y="0" width="318"
height="450" id="treeXml"
dataProvider="{departmentTree}" labelField="@name"
showDataTips="true" iconFunction="SetIcon" />
</mx:Application>
最后,运行效果即可。
首先,在src下建立一个assets文件夹,放几张图片;
其次,编写代码如下:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" fontSize="14" layout="absolute">
<mx:Script>
<![CDATA[
[Embed(source="assets/boy.jpg")]
public var boyIcon:Class;
[Embed(source="assets/girl.jpg")]
public var girlIcon:Class;
// 根据结点的属性设置节点图标
private function SetIcon(item:Object):*
{
var xml:XML = item as XML;
if(xml.attribute("sex")=="boy")
{
return boyIcon;
}
else
{
return girlIcon; }
}
// Tree控件的数据源
[Bindable]
public var departmentTree:XML=
<member name="小李" sex="boy">
<member name="王志" sex="boy">
<member name="赵强" sex="boy" />
<member name="李丽" sex="girl" />
</member>
<member name="韩梅梅" sex="girl">
<member name="孙艳" sex="girl"/>
</member>
</member>
]]>
</mx:Script>
<mx:Tree x="216" y="0" width="318"
height="450" id="treeXml"
dataProvider="{departmentTree}" labelField="@name"
showDataTips="true" iconFunction="SetIcon" />
</mx:Application>
最后,运行效果即可。
展开全部
QTreeWidgetItem* pTreeItem = nullptr;
pTreeItem = new QTreeWidgetItem(ui->treeWidget, QStringList(QString("000")));
QIcon icon;
icon.addPixmap(QPixmap(":/treeitem_screen_selected.png"), QIcon::Selected);
icon.addPixmap(QPixmap(":/treeitem_screen.png"), QIcon::Normal);
pTreeItem->setIcon(0, icon);
pTreeItem = new QTreeWidgetItem(ui->treeWidget, QStringList(QString("000")));
QIcon icon;
icon.addPixmap(QPixmap(":/treeitem_screen_selected.png"), QIcon::Selected);
icon.addPixmap(QPixmap(":/treeitem_screen.png"), QIcon::Normal);
pTreeItem->setIcon(0, icon);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询