Modify the the background color of table using stylesheets

This commit is contained in:
Magne Sjaastad 2024-02-08 09:56:27 +01:00
parent 33dcd55561
commit d0a9b7cd0b
2 changed files with 19 additions and 6 deletions

View File

@ -193,9 +193,25 @@ void PdmUiTableViewEditor::configureAndUpdateUi( const QString& uiConfigName )
this->setRowSelectionLevel( editorAttrib.rowSelectionLevel );
this->enableHeaderText( editorAttrib.enableHeaderText );
QPalette myPalette( m_tableView->palette() );
myPalette.setColor( QPalette::Base, editorAttrib.baseColor );
m_tableView->setPalette( myPalette );
QString styleSheetTable;
QString styleSheetHeader;
if ( editorAttrib.baseColor.isValid() )
{
// Configure style sheet to set the background color of the table and headers, including the corner button
styleSheetTable = QString( "QTableView QTableCornerButton::section { background: %1 } QTableView { "
"background-color : %1 } " )
.arg( editorAttrib.baseColor.name() );
styleSheetHeader =
QString( "QHeaderView { background-color: %1 } QHeaderView::section { background-color: %1 }" )
.arg( editorAttrib.baseColor.name() );
}
m_tableView->setStyleSheet( styleSheetTable );
m_tableView->horizontalHeader()->setStyleSheet( styleSheetHeader );
m_tableView->verticalHeader()->setStyleSheet( styleSheetHeader );
// Drop target settings
m_tableView->setAcceptDrops( editorAttrib.enableDropTarget );

View File

@ -107,11 +107,8 @@ public:
, resizePolicy( NO_AUTOMATIC_RESIZE )
, enableDropTarget( false )
{
QPalette myPalette;
baseColor = myPalette.color( QPalette::Active, QPalette::Base );
}
int selectionLevel;
int tableSelectionLevel;
int rowSelectionLevel;
bool enableHeaderText;