Reputation: 857
I am developing an app in which I am using QTableWidgets, and I need to set their background transparent, I have tried to setStyleSheet "background:transparent;"
, but nothing happened.
Is there any other way to do it?
Upvotes: 5
Views: 8116
Reputation: 11
Using background-color: rgba(0,0,0,0);
in your stylesheet, you can get a transparent table. Also, changing the alpha channel, you can have a great effect on your table.
Example:
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;
}
Upvotes: 0
Reputation: 8788
You're on the right track. Try:
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);
Note that I'm setting the style sheet before creating the table widget. I don't know why, but that seems to be necessary.
Upvotes: 14