5

I am developing an app in which I am using QTableWidgets, and I need to set its background transparent, I have tried to setStyleSheet "background:transparent;" from form, but nothing happened, is there any other way to do it? I am posting a screenshot

enter image description here

Ilya
  • 4,583
  • 4
  • 26
  • 51
abhishek
  • 857
  • 3
  • 13
  • 34

2 Answers2

14

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.

Anthony
  • 8,570
  • 3
  • 38
  • 46
0

Using background-color: rgba(0,0,0,0); on your stylesheet you can get transparent table. Also, changing Alpha channel, you can have 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;
}