• 先上一張效果圖如下::

  • 用 qt 繪製出所需要的線的樣式: 
line.png

繪製程式碼: 

    QImage pixmap(50,36, QImage::Format_ARGB32);  //繪圖裝置
    
    QPen pen;           //畫筆
    pen.setWidth(1);
    pen.setColor(Qt::black);
    pen.setStyle(Qt::DotLine);
    QPainter p(&pixmap);//畫家
    p.setPen(pen);
    p.drawLine(15, 20, 40, 20);
    p.drawLine(15, 0, 15, 20);
   
    pixmap.save("../line.png");
  • 網上找的加減號圖示 

 

 

  •  給樹新增樣式(結合以上素材)
ui.treeView->setStyleSheet( "QTreeView::item{height: 30px;show-decoration-selected: 0;}"
			                    "QTreeView::branch:open:has-children         
                               {image:url(:/tree/Resources/commit/ctr/jian.png);}"
                                "QTreeView::branch:closed:has-children 
                               {image:url(:/tree/Resources/commit/ctr/jia.png); }"
								"QTreeView::branch:has-siblings:adjoins-item
                            {border-image:  url(:/tree/Resources/tree/branch_more.png) 0;}"
								"QTreeView::branch:!has-children:!has-siblings:adjoins-item 
                              {border-image: url(:/tree/Resources/tree/branch_end.png) 0;}"
							 );

ui.treeView->expandAll();        //初始化樹的狀態為展開