Qt修改图片的背景色及设置背景色为透明的方法

本文介绍了在Qt环境下两种修改图片背景色的方法,包括一种暴力但实用的方法和另一种相对节省资源的技巧。同时,文章讲解了如何将图片背景色设置为透明,通过设置图片的alpha通道实现。注意保存透明图片时选择支持alpha通道的png格式。
摘要由CSDN通过智能技术生成

先上干货。

Qt下修改图片背景色的方法:

方法一:

QPixmap CKnitWidget::ChangeImageColor(QPixmap sourcePixmap, QColor origColor, QColor destColor)
{
QImage image = sourcePixmap.toImage();
for(int w = 0;w < image.width();++w)
for(int h = 0; h < image.height();++h)
{
QRgb rgb = image.pixel(w,h);
if(rgb == origColor.rgb())
{
///
修改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、付费专栏及课程。

余额充值