The blue selection background color of the attribute table rows is the default style of the QTableView
widget in the Qt GUI library on which QGIS is built.
Maybe there is a better way, but here is a slightly hacky but effective method to change it on a per-project basis by using a project Python macro and setting a style sheet on the QTableView
when the attribute table dialog is opened. The current canvas selection color is retrieved and used as the background color in the style sheet.
Note that if the selection color is yellow, the default white font color of selected items is very difficult to see so this solution also changes that to black.
Also note that, in it's current form, this works for one open attribute table at a time. If an additional attribute table is opened (i.e. you have two tables open at the same time) the one opened second will not be affected. This behavior could be modified fairly easily if required.
*I have tested this on Windows and Ubuntu and it works on both of those OS's. Not sure about mac.
Under the Project menu, select Properties and open the Macros tab. First you need to check the Python macros checkbox, then paste in the code block below and click OK.
from qgis.core import QgsApplication
from qgis.utils import iface
from qgis.PyQt.QtWidgets import QTableView
def windowFocusChanged(off, on):
tbl_dlgs = [w for w in app.allWidgets() if 'QgsAttributeTableDialog' in w.objectName()]
if tbl_dlgs:
tbl_dlg = tbl_dlgs[0]
tbl_view = tbl_dlg.findChild(QTableView)
selection_color = iface.mapCanvas().selectionColor().rgba64()
r_val = selection_color.red8()
g_val = selection_color.green8()
b_val = selection_color.blue8()
tbl_view.setStyleSheet(f"selection-background-color: rgb({r_val}, {g_val}, {b_val});\
selection-color: rgb(0, 0, 0);")
def openProject():
global app
app = QgsApplication.instance()
app.focusChanged.connect(windowFocusChanged)
def saveProject():
pass
def closeProject():
app.focusChanged.disconnect(windowFocusChanged)
See screenshot below:
You will then need to reload the project for the macro to take effect.
Results below:
Note that whenever you open the project you will be prompted to enable macros via the message bar:
You can avoid this by enabling macros for the current session under Settings>>Options>>General>>Project Files.
Or you could also do this with pyqgis via a startup.py file.