1

How can I change the appearance of the attribute table in QGIS, so that I can view the cell's font an its size smaller in my computer's screen?

Vince
  • 20,017
  • 15
  • 45
  • 64

1 Answers1

2

You should look at below code to change configuration. We copy a config file for column with for a particular layer. We choose to set for all columns a width of 250. By default, width = -1 (for auto size)

With this code, you can play to hide columns, change their orders, change their width, tell if they are a field column or an action column

layer = iface.activeLayer()
copy_columns = []
attributeTableConfig = QgsAttributeTableConfig()
# Plaything you can use to revert the order of column if used
# for i in reversed(layer.attributeTableConfig().columns()):
for i in layer.attributeTableConfig().columns():
    colConfig = attributeTableConfig.ColumnConfig()
    colConfig.hidden = i.hidden
    colConfig.name = i.name # You may use this name to custom each col size depending of your knowledge of custom content in each column name
    colConfig.type = i.type
    colConfig.width = 250
    copy_columns.append(colConfig)

attributeTableConfig.setColumns(copy_columns)

layer.setAttributeTableConfig(attributeTableConfig)

Old (only about fonts)

You may use the following content in a custom.qss file and load it as a new theme using plugin "Load QSS - UI themes"

QgsAttributeTableView, QHeaderView {
  font-size: 8px;
}

You may look at QSS reference at https://doc.qt.io/qt-5/stylesheet-reference.html to learn more

Below an overview result before/after

Default style

Style after QSS changes

ThomasG77
  • 30,725
  • 1
  • 53
  • 93