我正在开发一个应用程序,我在其中使用QTableWidgets,我需要将其背景设置为透明,我尝试从表单
setStyleSheet "background:transparent;"
,但没有任何反应,还有其他方法吗?我发截图
你在正确的轨道上。尝试:
setStyleSheet("QTableWidget {background-color: transparent;}"
"QHeaderView::section {background-color: transparent;}"
"QHeaderView {background-color: transparent;}"
"QTableCornerButton::section {background-color: transparent;}");
QTableWidget *table = new QTableWidget(latticeView);
table->setRowCount(2);
table->setColumnCount(2);
请注意,我在创建表格小部件之前设置了样式表。我不知道为什么,但这似乎是必要的。
在您的样式表上使用
background-color: rgba(0,0,0,0);
,您可以获得透明表格。另外,改变阿尔法通道,你可以对你的桌子产生很大的影响。
例子:
background-color: rgba(0,0,0,50);
QTableWidget
{
background-color: rgba(0,0,0,50);
color: rgb(255, 255, 255);
font-size:22px;
}
QTableWidget::item
{
color: rgb(255, 255, 255);
background-color:rgba(0,0,0,150);
text-align:center;
}
QTableWidget::item:hover
{
color:#FFFFFF;
background: #4B4B4D;
}
QTableWidget::item:selected
{
color:#FFFFFF;
background: #4B4B4D;
}
QHeaderView{
background-color: rgba(0,0,0,70);
}
QHeaderView::section,QTableCornerButton:section
{
text-align:center;
padding:3px;
margin:0px;
color: rgb(255, 255, 255);
background-color: rgba(0,0,0,70);
border:1px solid #242424;
border-radius: 8px;
}
QHeaderView::section:selected
{
color:#FFFFFF;
border:1px solid #242424;
}