perhaps i didn't explain well enough what I am doing. I am coloring the rows in a QTableWidget in alternating colors, but 2 rows 1 color, then 2 rows the other. The only way I have found so far was to color the cells as I generate the rows:
ui.tablewidget->item(0, 3)->setBackground(highlightBrush);
ui.tablewidget->item(0, 4)->setBackground(highlightBrush);
//etc...
ui.tablewidget->item(0, 3)->setBackground(highlightBrush);
ui.tablewidget->item(0, 4)->setBackground(highlightBrush);
//etc...
To copy to clipboard, switch view to plain text mode
This works, however it does not completely match the base and alternate base color (because I don't know how to construct brushes that take from those colors)
The background role method:
//this produces errors as a qtablewidgetitem does not have setBackgroundRole()
ui.
tableWidget->item
(0,
1)->setBackgroundRole
(QPalette::AlternateBase);
ui.
tableWidget->item
(0,
2)->setBackgroundRole
(QPalette::Base);
//this produces errors as a qtablewidgetitem does not have setBackgroundRole()
ui.tableWidget->item(0, 1)->setBackgroundRole(QPalette::AlternateBase);
ui.tableWidget->item(0, 2)->setBackgroundRole(QPalette::Base);
To copy to clipboard, switch view to plain text mode
Will not work because QTableWidgetItem does not accept setBackgroundRole, it only accepts a brush in setBackground()
so all I need to know really, is how to create a brush from the color used in QPalette::AlternateBase and QPalette::Base or use the existing brush for those colors (but how to reference it I have no clue.
Bookmarks