如何修改treeview的背景色

<script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>

在通常情况下,treeview背景色是不可以修改的,我们可以通过API实现,源码如下

Option Explicit

Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
Private Declare Function GetWindowLong Lib "User32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "User32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Private Const GWL_STYLE = -16&
Private Const TVM_SETBKCOLOR = 4381&
Private Const TVM_GETBKCOLOR = 4383&
Private Const TVS_HASLINES = 2&

Private Sub Form_Load()

Dim nodex As Node
Dim i As Integer
Dim lStyle As Long

Call SendMessage(treeview1.hWnd, TVM_SETBKCOLOR, 0, ByVal RGB(255, 0, 0))
lStyle = GetWindowLong(treeview1.hWnd, GWL_STYLE)
Call SetWindowLong(treeview1.hWnd, GWL_STYLE, lStyle - TVS_HASLINES)
Call SetWindowLong(treeview1.hWnd, GWL_STYLE, lStyle)

treeview1.Style = tvwTreelinesPlusMinusPictureText
treeview1.BorderStyle = ccFixedSingle
With treeview1.Nodes
Set nodex = .Add(, , "R", "Root")
nodex.BackColor = RGB(255, 0, 0)
For i = 1 To 10
    Set nodex = .Add("R", tvwChild, "C" & i, "Child " & i)
    nodex.BackColor = RGB(255, 0, 0)
    nodex.EnsureVisible
Next
End With

End Sub

 

 

<script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
修改QT TreeView背景色,可以按照以下步骤进行操作: 1. 找到QTreeView的样式文件或者QSS文件,在文件中找到对应的QTreeView选择器。 2. 在选择器中修改show-decoration-selected属性的值为0,这将解决TreeView背景色问题。 3. 如果想要实现整行的背景色相同,可以继续在样式文件或者QSS文件中添加以下代码: QTreeView::item:hover, QTreeView::branch:hover { background-color: rgba(xx, xx, xx, xx); } QTreeView::item:selected, QTreeView::branch:selected { background-color: rgba(xx, xx, xx, xx); } QTreeView::item:selected:!active, QTreeView::branch:selected:!active { background-color: rgba(xx, xx, xx, xx); } 这样可以设置item(箭头右侧部分)和branch(左侧部分)的颜色来实现整条的背景色相同。 4. 如果想要控制显示整行的背景色,可以在QTreeView的样式文件或者QSS文件中添加如下语句: show-decoration-selected: 1; 这将控制显示整行的背景色。 通过以上步骤,你可以修改QT TreeView背景色并实现你想要的效果。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Qt TreeView选中节点取消背景色](https://blog.csdn.net/weixin_41001497/article/details/121656173)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [QTreeView 设置背景色应用于整条](https://blog.csdn.net/qq_41834573/article/details/117397457)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值