当前位置:   article > 正文

QtPropertyBrowser(QtTreePropertyBrowser)改变Qss样式的几种方法!_qttreepropertybrowser 样式

qttreepropertybrowser 样式

QtPropertyBrowser 从 QtTreePropertyBrowser、QtGroupBoxPropertyBrowser、QtButtonPropertyBrowser这三个入口。这三个是QWidget。用得比较多的是第一个QtTreePropertyBrowser,这是一个QTreeView。

方法一:
第一步:设置QSS样式的时候,从以上三个入口设置。QtTreePropertyBrowser设置QSS等同于一个QTreeView,QtTreePropertyBrowser设置背景色有些麻烦,需要设置alternate-background-color,设置隔行背景色效果。
或者用*QtTreePropertyBrowser::setAlternatingRowColors(false);*取消隔行差异效果。
第二步:当取消行颜色差异之后,就可以设置背景颜色了,其实就是对应QSS的QTreeWidget。比如:

QTreeWidget{
	background-color: rgb(37, 41, 76);
	color: white;
}
  • 1
  • 2
  • 3
  • 4

效果如下:
在这里插入图片描述

其实QTreeView的样式也有一部分适用于QtTreePropertyBrowser,但是设置QTreeView的背景颜色时,QtTreePropertyBrowser没有跟着变。

方法二:

设置指定单行的颜色样式,部分代码:

item = pVarManager->addProperty(QVariant::Double, tr("浮点数据"));
item->setAttribute(QLatin1String("decimals"), 5);
item->setValue(3.1415926);
ui->widget->addProperty(item);

item = pVarManager->addProperty(QVariant::String, tr("字符串数据"));
item->setValue(tr("你好!世界!"));
QtBrowserItem *p = ui->widget->addProperty(item);

//设置字符串数据所在行背景色
ui->widget->setBackgroundColor(p, QColor(qRgb(255, 255, 0)));
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

效果如下:
在这里插入图片描述
未完待续!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/299565
推荐阅读
相关标签
  

闽ICP备14008679号