2012-04-25 137 views
1

我正在開發一個應用程序,其中我使用QTableWidgets,並且我需要將其背景設置爲透明,我嘗試從表單中嘗試setStyleSheet "background:transparent;",但沒有任何事情發生,是否有任何其他方式可以執行此操作?我張貼的截圖如何在Qt中設置QTableWidget背景透明?

enter image description here

回答

7

你在正確的軌道上。嘗試:

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); 

請注意,我在創建表小部件之前設置樣式表。我不知道爲什麼,但似乎是必要的。