-
Notifications
You must be signed in to change notification settings - Fork 731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Font role not taken into account for table header #315
Comments
Describe Your Environment QDarkStyle: 3.0.2 and also 3.1 from PyPi OS: Windows 10 22H2 Description / Steps to Reproduce [if necessary] minimum working example: # inspired by https://www.pythonguis.com/tutorials/qtableview-modelviews-numpy-pandas/
import sys
import numpy as np
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import Qt
import qdarkstyle
class TableModel(QtCore.QAbstractTableModel):
def __init__(self, data, horizontal_headers,**kwargs):
super(TableModel, self).__init__()
self._data = data
self._horizontal_headers = horizontal_headers
if 'font' in kwargs.keys():
self._font = QtGui.QFont(kwargs['font'])
else:
self._font = QtGui.QFont()
if 'fontsize' in kwargs.keys():
self._font.setPixelSize(kwargs['fontsize'])
else:
self._font.setPixelSize(12)
def data(self, index, role) -> str:
"""method for visualization of the data model"""
# display
if role == Qt.DisplayRole:
datum = self._data[index.row(),index.column()]
return str(datum)
# set fonts
if role == Qt.FontRole:
return self._font
def rowCount(self, index):
return self._data.shape[0]
def columnCount(self, index):
return self._data.shape[1]
def headerData(self, section, orientation, role):
# section is the index of the column/row.
if role == Qt.DisplayRole:
if orientation == Qt.Horizontal:
return str(self._horizontal_headers[section])
if orientation == Qt.Vertical:
return str(section)
# set fonts for headers
if role == Qt.FontRole:
return self._font
class MainWindow(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
self.table = QtWidgets.QTableView()
data = np.array([
[4, 9, 2],
[1, 0, 0],
[3, 5, 0],
[3, 3, 2],
[7, 8, 9],
],dtype=int)
self.model = TableModel(data,['A','B','C'],font='Arial', fontsize=9)
self.table.setModel(self.model)
self.setCentralWidget(self.table)
if __name__ == "__main__":
app=QtWidgets.QApplication(sys.argv)
dark_stylesheet = qdarkstyle.load_stylesheet_pyqt5()
app.setStyleSheet(dark_stylesheet)
window=MainWindow()
window.show()
app.exec_() Actual Results Expected Results / Proposed Result Commenting out dark_stylesheet = qdarkstyle.load_stylesheet_pyqt5()
app.setStyleSheet(dark_stylesheet) and using standard style works as intended. |
Describe Your Environment
[Versions from your environment]
Language
C++
Description / Steps to Reproduce [if necessary]
I made these changes to sqlitebrowser to get column headers with some font decorations (underlined and cursive):
sqlitebrowser/sqlitebrowser@b6c5024
The change works as expected when using the standard desktop style.
Actual Result
No noticable change, every column header has a regular font.
Expected Results / Proposed Result
Primary Key columns are underlined, foreign key columns are cursive.
Shouldn't work the style sheet as the default style?
The text was updated successfully, but these errors were encountered: