首页 > 代码库 > QTreeView使用点点滴滴

QTreeView使用点点滴滴

QTreeView比较复杂,在这里记下所有用到的操作:

-----------------------------------------------------------------------------

如何给QTreeView的节点显示图标
要显示节点图标,就在重写模型的时候在DecorationRole角色时返回要显示的图标就可以了

    Node *node = nodeFromIndex(index);    if (role == Qt::DecorationRole){        switch(node->item){            case Node::    Root:                return QIcon(":/images/ras.ico");            case Node::Downloading:                return QIcon(":/images/Download.png");            case Node::Downloaded:                return QIcon(":/images/Misc-Stuff.png");            case Node::Daily:                return QIcon(":/images/Database.png");            case Node::Timespace:                return QIcon(":/images/Software.ico");        }    }

 

QTreeView使用点点滴滴