BCDA-APS / gemviz

Data visualization for tiled
https://bcda-aps.github.io/gemviz/
Other
4 stars 0 forks source link

Center column text via role instead of delegate #159

Closed prjemian closed 6 months ago

prjemian commented 1 year ago

While researching Qt.BackgroundRole, I found this list of common roles in the QAbstractItemModel class for different kinds of data and formatting:

Qt.DisplayRole: Data to be rendered as text. Qt.DecorationRole: Data to be rendered as an icon. Qt.EditRole: Data that can be edited. Qt.ToolTipRole: Data to be displayed as a tooltip. Qt.StatusTipRole: Data to be displayed in a status bar. Qt.WhatsThisRole: Data that can be used to populate "What's This?" help messages. Qt.FontRole: Font used to display data. Qt.TextAlignmentRole: Alignment of the data. Qt.BackgroundRole: Background color. Qt.ForegroundRole: Foreground color (e.g., text color). Qt.CheckStateRole: Check state (e.g., for checkable items).

We could use Qt.TextAlignmentRole instead of a delegate to center the "Scan ID" and "#points" in the table:

if role == Qt.TextAlignmentRole:
        if index.column() in [0,4]:
            return Qt.AlignCenter
        else:
            return Qt.AlignLeft

Originally posted by @rodolakis in https://github.com/BCDA-APS/gemviz/issues/157#issuecomment-1706800894

prjemian commented 1 year ago

See this documentation: https://doc.qt.io/qtforpython-5/PySide2/QtCore/Qt.html#PySide2.QtCore.PySide2.QtCore.Qt.ItemDataRole

prjemian commented 1 year ago

Rather than select by column number, match with column name

prjemian commented 6 months ago

before

before

after

after